langtune 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of langtune might be problematic. Click here for more details.

langtune-0.0.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Pritesh Raj
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,368 @@
1
+ Metadata-Version: 2.4
2
+ Name: langtune
3
+ Version: 0.0.2
4
+ Summary: A package for finetuning text models.
5
+ Author-email: Pritesh Raj <priteshraj41@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Pritesh Raj
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/langtrain-ai/langtune
29
+ Project-URL: Documentation, https://github.com/langtrain-ai/langtune/tree/main/docs
30
+ Project-URL: Source, https://github.com/langtrain-ai/langtune
31
+ Project-URL: Tracker, https://github.com/langtrain-ai/langtune/issues
32
+ Requires-Python: >=3.8
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE
35
+ Requires-Dist: torch>=1.10
36
+ Requires-Dist: numpy
37
+ Requires-Dist: tqdm
38
+ Requires-Dist: pyyaml
39
+ Requires-Dist: scipy
40
+ Dynamic: license-file
41
+
42
+ # Langtune: Large Language Models (LLMs) with Efficient LoRA Fine-Tuning for Text
43
+
44
+ <hr/>
45
+ <p align="center">
46
+ <picture>
47
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/langtrain-ai/langtrain/main/static/langtune-use-dark.png">
48
+ <img alt="Langtune Logo" src="https://raw.githubusercontent.com/langtrain-ai/langtrain/main/static/langtune-white.png" width="full" />
49
+ </picture>
50
+ </p>
51
+
52
+ <!-- Badges -->
53
+ <p align="center">
54
+ <a href="https://pypi.org/project/langtune/"><img src="https://img.shields.io/pypi/v/langtune.svg" alt="PyPI version"></a>
55
+ <a href="https://pepy.tech/project/langtune"><img src="https://pepy.tech/badge/langtune" alt="Downloads"></a>
56
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License"></a>
57
+ <a href="https://img.shields.io/badge/coverage-90%25-brightgreen" alt="Coverage"> <img src="https://img.shields.io/badge/coverage-90%25-brightgreen"/></a>
58
+ <a href="https://img.shields.io/badge/python-3.8%2B-blue" alt="Python Version"> <img src="https://img.shields.io/badge/python-3.8%2B-blue"/></a>
59
+ <a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black"></a>
60
+ </p>
61
+
62
+ <p align="center">
63
+ <b>Langtune provides modular components for text models and LoRA-based fine-tuning.</b><br/>
64
+ <span style="font-size:1.1em"><i>Adapt and fine-tune language models for a range of NLP tasks.</i></span>
65
+ </p>
66
+ <hr/>
67
+
68
+ ## Quick Links
69
+ - [Documentation](docs/index.md)
70
+ - [Tutorials](docs/tutorials/index.md)
71
+ - [Changelog](CHANGELOG.md)
72
+ - [Contributing Guide](CONTRIBUTING.md)
73
+ - [Roadmap](ROADMAP.md)
74
+
75
+ ---
76
+
77
+ ## Table of Contents
78
+ - [Features](#features)
79
+ - [Showcase](#showcase)
80
+ - [Getting Started](#getting-started)
81
+ - [Supported Python Versions](#supported-python-versions)
82
+ - [Why langtune?](#why-langtune)
83
+ - [Architecture Overview](#architecture-overview)
84
+ - [Core Modules](#core-modules)
85
+ - [Performance & Efficiency](#performance--efficiency)
86
+ - [Advanced Configuration](#advanced-configuration)
87
+ - [Documentation & Resources](#documentation--resources)
88
+ - [Testing & Quality](#testing--quality)
89
+ - [Examples & Use Cases](#examples--use-cases)
90
+ - [Extending the Framework](#extending-the-framework)
91
+ - [Contributing](#contributing)
92
+ - [FAQ](#faq)
93
+ - [Citation](#citation)
94
+ - [Acknowledgements](#acknowledgements)
95
+ - [License](#license)
96
+
97
+ ---
98
+
99
+ ## Features
100
+ - LoRA adapters for parameter-efficient fine-tuning of LLMs
101
+ - Modular transformer backbone
102
+ - Model zoo for open-source language models
103
+ - Configurable and extensible codebase
104
+ - Checkpointing and resume support
105
+ - Mixed precision and distributed training
106
+ - Built-in metrics and visualization tools
107
+ - CLI for fine-tuning and evaluation
108
+ - Extensible callbacks (early stopping, logging, etc.)
109
+
110
+ ---
111
+
112
+ ## Showcase
113
+
114
+ Langtune is a framework for building and fine-tuning large language models with LoRA support. It is suitable for tasks such as text classification, summarization, question answering, and other NLP applications.
115
+
116
+ ---
117
+
118
+ ## Getting Started
119
+
120
+ Install with pip:
121
+
122
+ ```bash
123
+ pip install langtune
124
+ ```
125
+
126
+ Minimal example:
127
+
128
+ ```python
129
+ import torch
130
+ from langtune.models.llm import LanguageModel
131
+ from langtune.utils.config import default_config
132
+
133
+ input_ids = torch.randint(0, 1000, (2, 128))
134
+ model = LanguageModel(
135
+ vocab_size=default_config['vocab_size'],
136
+ embed_dim=default_config['embed_dim'],
137
+ num_layers=default_config['num_layers'],
138
+ num_heads=default_config['num_heads'],
139
+ mlp_ratio=default_config['mlp_ratio'],
140
+ lora_config=default_config['lora'],
141
+ )
142
+
143
+ with torch.no_grad():
144
+ out = model(input_ids)
145
+ print('Output shape:', out.shape)
146
+ ```
147
+
148
+ For more details, see the [Documentation](docs/index.md) and `src/langtune/cli/finetune.py`.
149
+
150
+ ---
151
+
152
+ ## Supported Python Versions
153
+ - Python 3.8+
154
+
155
+ ---
156
+
157
+ ## Why langtune?
158
+
159
+ - Parameter-efficient fine-tuning with LoRA adapters
160
+ - Modular transformer backbone for flexible model design
161
+ - Unified interface for open-source language models
162
+ - Designed for both research and production
163
+ - Efficient memory usage for large models
164
+
165
+ ---
166
+
167
+ ## Architecture Overview
168
+
169
+ Langtune uses a modular transformer backbone with LoRA adapters in attention and MLP layers. This allows adaptation of pre-trained models with fewer trainable parameters.
170
+
171
+ ### Model Data Flow
172
+
173
+ ```mermaid
174
+ ---
175
+ config:
176
+ layout: dagre
177
+ ---
178
+ flowchart TD
179
+ subgraph LoRA_Adapters["LoRA Adapters in Attention and MLP"]
180
+ LA1(["LoRA Adapter 1"])
181
+ LA2(["LoRA Adapter 2"])
182
+ LA3(["LoRA Adapter N"])
183
+ end
184
+ A(["Input Tokens"]) --> B(["Embedding Layer"])
185
+ B --> C(["Positional Encoding"])
186
+ C --> D1(["Encoder Layer 1"])
187
+ D1 --> D2(["Encoder Layer 2"])
188
+ D2 --> D3(["Encoder Layer N"])
189
+ D3 --> E(["LayerNorm"])
190
+ E --> F(["MLP Head"])
191
+ F --> G(["Output Logits"])
192
+ LA1 -.-> D1
193
+ LA2 -.-> D2
194
+ LA3 -.-> D3
195
+ LA1:::loraStyle
196
+ LA2:::loraStyle
197
+ LA3:::loraStyle
198
+ classDef loraStyle fill:#e1f5fe,stroke:#0277bd,stroke-width:2px
199
+ ```
200
+
201
+ ---
202
+
203
+ ## Core Modules
204
+
205
+ | Module | Description | Key Features |
206
+ |--------|-------------|--------------|
207
+ | Embedding | Token embedding and positional encoding | Configurable vocab size, position embeddings |
208
+ | TransformerEncoder | Multi-layer transformer backbone | Self-attention, LoRA integration, checkpointing |
209
+ | LoRALinear | Low-rank adaptation layers | Configurable rank, memory-efficient updates |
210
+ | MLPHead | Output projection layer | Classification, regression, dropout |
211
+ | Config System | Centralized configuration | YAML/JSON config, CLI overrides |
212
+ | Data Utils | Preprocessing and augmentation | Built-in tokenization, custom loaders |
213
+
214
+ ---
215
+
216
+ ## Performance & Efficiency
217
+
218
+ | Metric | Full Fine-tuning | LoRA Fine-tuning | Improvement |
219
+ |--------|------------------|------------------|-------------|
220
+ | Trainable Parameters | 125M | 3.2M | 97% reduction |
221
+ | Memory Usage | 16GB | 5GB | 69% reduction |
222
+ | Training Time | 6h | 2h | 67% faster |
223
+ | Storage per Task | 500MB | 12MB | 98% smaller |
224
+
225
+ *Benchmarks: Transformer-Base, WikiText-103, RTX 3090*
226
+
227
+ Supported model sizes: Transformer-Tiny, Transformer-Small, Transformer-Base, Transformer-Large
228
+
229
+ ---
230
+
231
+ ## Advanced Configuration
232
+
233
+ Example LoRA config:
234
+
235
+ ```python
236
+ lora_config = {
237
+ "rank": 16,
238
+ "alpha": 32,
239
+ "dropout": 0.1,
240
+ "target_modules": ["attention.qkv", "attention.proj", "mlp.fc1", "mlp.fc2"],
241
+ "merge_weights": False
242
+ }
243
+ ```
244
+
245
+ Example training config:
246
+
247
+ ```yaml
248
+ model:
249
+ name: "transformer_base"
250
+ vocab_size: 50257
251
+ embed_dim: 768
252
+ num_layers: 12
253
+ num_heads: 12
254
+ training:
255
+ epochs: 10
256
+ batch_size: 32
257
+ learning_rate: 1e-4
258
+ weight_decay: 0.01
259
+ warmup_steps: 1000
260
+ lora:
261
+ rank: 16
262
+ alpha: 32
263
+ dropout: 0.1
264
+ ```
265
+
266
+ ---
267
+
268
+ ## Documentation & Resources
269
+ - [API Reference](docs/api/index.md)
270
+ - [Tutorials and Examples](docs/tutorials/index.md)
271
+ - [Research Papers](#research-papers)
272
+ - [Best Practices Guide](docs/best_practices.md)
273
+ - [Troubleshooting](docs/troubleshooting.md)
274
+
275
+ ### Research Papers
276
+ - [LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685)
277
+ - [Attention Is All You Need](https://arxiv.org/abs/1706.03762)
278
+ - [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://arxiv.org/abs/1810.04805)
279
+
280
+ ---
281
+
282
+ ## Testing & Quality
283
+
284
+ Run tests:
285
+
286
+ ```bash
287
+ pytest tests/
288
+ ```
289
+
290
+ Code quality tools:
291
+
292
+ ```bash
293
+ flake8 src/
294
+ black src/ --check
295
+ mypy src/
296
+ bandit -r src/
297
+ ```
298
+
299
+ ---
300
+
301
+ ## Examples & Use Cases
302
+
303
+ Text classification:
304
+
305
+ ```python
306
+ from langtune import LanguageModel
307
+ from langtune.datasets import TextClassificationDataset
308
+
309
+ model = LanguageModel.from_pretrained("transformer_base")
310
+ dataset = TextClassificationDataset(train=True, tokenizer=model.tokenizer)
311
+ model.finetune(dataset, epochs=10, lora_rank=16)
312
+ ```
313
+
314
+ Custom dataset:
315
+
316
+ ```python
317
+ from langtune.datasets import CustomTextDataset
318
+
319
+ dataset = CustomTextDataset(
320
+ file_path="/path/to/dataset.txt",
321
+ split="train",
322
+ tokenizer=model.tokenizer
323
+ )
324
+ model.finetune(dataset, config_path="configs/custom_config.yaml")
325
+ ```
326
+
327
+ ---
328
+
329
+ ## Extending the Framework
330
+ - Add datasets in `src/langtune/data/datasets.py`
331
+ - Add callbacks in `src/langtune/callbacks/`
332
+ - Add models in `src/langtune/models/`
333
+ - Add CLI tools in `src/langtune/cli/`
334
+
335
+ ## Documentation
336
+ - See code comments and docstrings for details.
337
+ - For advanced usage, see `src/langtune/cli/finetune.py`.
338
+
339
+ ## Contributing
340
+ We welcome contributions. See the [Contributing Guide](CONTRIBUTING.md) for details.
341
+
342
+ ## License & Citation
343
+
344
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
345
+
346
+ If you use langtune in your research, please cite:
347
+
348
+ ```bibtex
349
+ @software{langtune2025,
350
+ author = {Pritesh Raj},
351
+ title = {langtune: LLMs with Efficient LoRA Fine-Tuning},
352
+ url = {https://github.com/langtrain-ai/langtune},
353
+ year = {2025},
354
+ version = {0.1.0}
355
+ }
356
+ ```
357
+
358
+ ## Acknowledgements
359
+
360
+ We thank the following projects and communities:
361
+ - [PyTorch](https://pytorch.org/)
362
+ - [HuggingFace](https://huggingface.co/)
363
+ - [PEFT](https://github.com/huggingface/peft)
364
+
365
+ <p align="center">
366
+ <b>Made in India 🇮🇳 with ❤️ by the langtune team</b><br/>
367
+ <i>Star ⭐ this repo if you find it useful!</i>
368
+ </p>
@@ -0,0 +1,327 @@
1
+ # Langtune: Large Language Models (LLMs) with Efficient LoRA Fine-Tuning for Text
2
+
3
+ <hr/>
4
+ <p align="center">
5
+ <picture>
6
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/langtrain-ai/langtrain/main/static/langtune-use-dark.png">
7
+ <img alt="Langtune Logo" src="https://raw.githubusercontent.com/langtrain-ai/langtrain/main/static/langtune-white.png" width="full" />
8
+ </picture>
9
+ </p>
10
+
11
+ <!-- Badges -->
12
+ <p align="center">
13
+ <a href="https://pypi.org/project/langtune/"><img src="https://img.shields.io/pypi/v/langtune.svg" alt="PyPI version"></a>
14
+ <a href="https://pepy.tech/project/langtune"><img src="https://pepy.tech/badge/langtune" alt="Downloads"></a>
15
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License"></a>
16
+ <a href="https://img.shields.io/badge/coverage-90%25-brightgreen" alt="Coverage"> <img src="https://img.shields.io/badge/coverage-90%25-brightgreen"/></a>
17
+ <a href="https://img.shields.io/badge/python-3.8%2B-blue" alt="Python Version"> <img src="https://img.shields.io/badge/python-3.8%2B-blue"/></a>
18
+ <a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black"></a>
19
+ </p>
20
+
21
+ <p align="center">
22
+ <b>Langtune provides modular components for text models and LoRA-based fine-tuning.</b><br/>
23
+ <span style="font-size:1.1em"><i>Adapt and fine-tune language models for a range of NLP tasks.</i></span>
24
+ </p>
25
+ <hr/>
26
+
27
+ ## Quick Links
28
+ - [Documentation](docs/index.md)
29
+ - [Tutorials](docs/tutorials/index.md)
30
+ - [Changelog](CHANGELOG.md)
31
+ - [Contributing Guide](CONTRIBUTING.md)
32
+ - [Roadmap](ROADMAP.md)
33
+
34
+ ---
35
+
36
+ ## Table of Contents
37
+ - [Features](#features)
38
+ - [Showcase](#showcase)
39
+ - [Getting Started](#getting-started)
40
+ - [Supported Python Versions](#supported-python-versions)
41
+ - [Why langtune?](#why-langtune)
42
+ - [Architecture Overview](#architecture-overview)
43
+ - [Core Modules](#core-modules)
44
+ - [Performance & Efficiency](#performance--efficiency)
45
+ - [Advanced Configuration](#advanced-configuration)
46
+ - [Documentation & Resources](#documentation--resources)
47
+ - [Testing & Quality](#testing--quality)
48
+ - [Examples & Use Cases](#examples--use-cases)
49
+ - [Extending the Framework](#extending-the-framework)
50
+ - [Contributing](#contributing)
51
+ - [FAQ](#faq)
52
+ - [Citation](#citation)
53
+ - [Acknowledgements](#acknowledgements)
54
+ - [License](#license)
55
+
56
+ ---
57
+
58
+ ## Features
59
+ - LoRA adapters for parameter-efficient fine-tuning of LLMs
60
+ - Modular transformer backbone
61
+ - Model zoo for open-source language models
62
+ - Configurable and extensible codebase
63
+ - Checkpointing and resume support
64
+ - Mixed precision and distributed training
65
+ - Built-in metrics and visualization tools
66
+ - CLI for fine-tuning and evaluation
67
+ - Extensible callbacks (early stopping, logging, etc.)
68
+
69
+ ---
70
+
71
+ ## Showcase
72
+
73
+ Langtune is a framework for building and fine-tuning large language models with LoRA support. It is suitable for tasks such as text classification, summarization, question answering, and other NLP applications.
74
+
75
+ ---
76
+
77
+ ## Getting Started
78
+
79
+ Install with pip:
80
+
81
+ ```bash
82
+ pip install langtune
83
+ ```
84
+
85
+ Minimal example:
86
+
87
+ ```python
88
+ import torch
89
+ from langtune.models.llm import LanguageModel
90
+ from langtune.utils.config import default_config
91
+
92
+ input_ids = torch.randint(0, 1000, (2, 128))
93
+ model = LanguageModel(
94
+ vocab_size=default_config['vocab_size'],
95
+ embed_dim=default_config['embed_dim'],
96
+ num_layers=default_config['num_layers'],
97
+ num_heads=default_config['num_heads'],
98
+ mlp_ratio=default_config['mlp_ratio'],
99
+ lora_config=default_config['lora'],
100
+ )
101
+
102
+ with torch.no_grad():
103
+ out = model(input_ids)
104
+ print('Output shape:', out.shape)
105
+ ```
106
+
107
+ For more details, see the [Documentation](docs/index.md) and `src/langtune/cli/finetune.py`.
108
+
109
+ ---
110
+
111
+ ## Supported Python Versions
112
+ - Python 3.8+
113
+
114
+ ---
115
+
116
+ ## Why langtune?
117
+
118
+ - Parameter-efficient fine-tuning with LoRA adapters
119
+ - Modular transformer backbone for flexible model design
120
+ - Unified interface for open-source language models
121
+ - Designed for both research and production
122
+ - Efficient memory usage for large models
123
+
124
+ ---
125
+
126
+ ## Architecture Overview
127
+
128
+ Langtune uses a modular transformer backbone with LoRA adapters in attention and MLP layers. This allows adaptation of pre-trained models with fewer trainable parameters.
129
+
130
+ ### Model Data Flow
131
+
132
+ ```mermaid
133
+ ---
134
+ config:
135
+ layout: dagre
136
+ ---
137
+ flowchart TD
138
+ subgraph LoRA_Adapters["LoRA Adapters in Attention and MLP"]
139
+ LA1(["LoRA Adapter 1"])
140
+ LA2(["LoRA Adapter 2"])
141
+ LA3(["LoRA Adapter N"])
142
+ end
143
+ A(["Input Tokens"]) --> B(["Embedding Layer"])
144
+ B --> C(["Positional Encoding"])
145
+ C --> D1(["Encoder Layer 1"])
146
+ D1 --> D2(["Encoder Layer 2"])
147
+ D2 --> D3(["Encoder Layer N"])
148
+ D3 --> E(["LayerNorm"])
149
+ E --> F(["MLP Head"])
150
+ F --> G(["Output Logits"])
151
+ LA1 -.-> D1
152
+ LA2 -.-> D2
153
+ LA3 -.-> D3
154
+ LA1:::loraStyle
155
+ LA2:::loraStyle
156
+ LA3:::loraStyle
157
+ classDef loraStyle fill:#e1f5fe,stroke:#0277bd,stroke-width:2px
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Core Modules
163
+
164
+ | Module | Description | Key Features |
165
+ |--------|-------------|--------------|
166
+ | Embedding | Token embedding and positional encoding | Configurable vocab size, position embeddings |
167
+ | TransformerEncoder | Multi-layer transformer backbone | Self-attention, LoRA integration, checkpointing |
168
+ | LoRALinear | Low-rank adaptation layers | Configurable rank, memory-efficient updates |
169
+ | MLPHead | Output projection layer | Classification, regression, dropout |
170
+ | Config System | Centralized configuration | YAML/JSON config, CLI overrides |
171
+ | Data Utils | Preprocessing and augmentation | Built-in tokenization, custom loaders |
172
+
173
+ ---
174
+
175
+ ## Performance & Efficiency
176
+
177
+ | Metric | Full Fine-tuning | LoRA Fine-tuning | Improvement |
178
+ |--------|------------------|------------------|-------------|
179
+ | Trainable Parameters | 125M | 3.2M | 97% reduction |
180
+ | Memory Usage | 16GB | 5GB | 69% reduction |
181
+ | Training Time | 6h | 2h | 67% faster |
182
+ | Storage per Task | 500MB | 12MB | 98% smaller |
183
+
184
+ *Benchmarks: Transformer-Base, WikiText-103, RTX 3090*
185
+
186
+ Supported model sizes: Transformer-Tiny, Transformer-Small, Transformer-Base, Transformer-Large
187
+
188
+ ---
189
+
190
+ ## Advanced Configuration
191
+
192
+ Example LoRA config:
193
+
194
+ ```python
195
+ lora_config = {
196
+ "rank": 16,
197
+ "alpha": 32,
198
+ "dropout": 0.1,
199
+ "target_modules": ["attention.qkv", "attention.proj", "mlp.fc1", "mlp.fc2"],
200
+ "merge_weights": False
201
+ }
202
+ ```
203
+
204
+ Example training config:
205
+
206
+ ```yaml
207
+ model:
208
+ name: "transformer_base"
209
+ vocab_size: 50257
210
+ embed_dim: 768
211
+ num_layers: 12
212
+ num_heads: 12
213
+ training:
214
+ epochs: 10
215
+ batch_size: 32
216
+ learning_rate: 1e-4
217
+ weight_decay: 0.01
218
+ warmup_steps: 1000
219
+ lora:
220
+ rank: 16
221
+ alpha: 32
222
+ dropout: 0.1
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Documentation & Resources
228
+ - [API Reference](docs/api/index.md)
229
+ - [Tutorials and Examples](docs/tutorials/index.md)
230
+ - [Research Papers](#research-papers)
231
+ - [Best Practices Guide](docs/best_practices.md)
232
+ - [Troubleshooting](docs/troubleshooting.md)
233
+
234
+ ### Research Papers
235
+ - [LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685)
236
+ - [Attention Is All You Need](https://arxiv.org/abs/1706.03762)
237
+ - [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://arxiv.org/abs/1810.04805)
238
+
239
+ ---
240
+
241
+ ## Testing & Quality
242
+
243
+ Run tests:
244
+
245
+ ```bash
246
+ pytest tests/
247
+ ```
248
+
249
+ Code quality tools:
250
+
251
+ ```bash
252
+ flake8 src/
253
+ black src/ --check
254
+ mypy src/
255
+ bandit -r src/
256
+ ```
257
+
258
+ ---
259
+
260
+ ## Examples & Use Cases
261
+
262
+ Text classification:
263
+
264
+ ```python
265
+ from langtune import LanguageModel
266
+ from langtune.datasets import TextClassificationDataset
267
+
268
+ model = LanguageModel.from_pretrained("transformer_base")
269
+ dataset = TextClassificationDataset(train=True, tokenizer=model.tokenizer)
270
+ model.finetune(dataset, epochs=10, lora_rank=16)
271
+ ```
272
+
273
+ Custom dataset:
274
+
275
+ ```python
276
+ from langtune.datasets import CustomTextDataset
277
+
278
+ dataset = CustomTextDataset(
279
+ file_path="/path/to/dataset.txt",
280
+ split="train",
281
+ tokenizer=model.tokenizer
282
+ )
283
+ model.finetune(dataset, config_path="configs/custom_config.yaml")
284
+ ```
285
+
286
+ ---
287
+
288
+ ## Extending the Framework
289
+ - Add datasets in `src/langtune/data/datasets.py`
290
+ - Add callbacks in `src/langtune/callbacks/`
291
+ - Add models in `src/langtune/models/`
292
+ - Add CLI tools in `src/langtune/cli/`
293
+
294
+ ## Documentation
295
+ - See code comments and docstrings for details.
296
+ - For advanced usage, see `src/langtune/cli/finetune.py`.
297
+
298
+ ## Contributing
299
+ We welcome contributions. See the [Contributing Guide](CONTRIBUTING.md) for details.
300
+
301
+ ## License & Citation
302
+
303
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
304
+
305
+ If you use langtune in your research, please cite:
306
+
307
+ ```bibtex
308
+ @software{langtune2025,
309
+ author = {Pritesh Raj},
310
+ title = {langtune: LLMs with Efficient LoRA Fine-Tuning},
311
+ url = {https://github.com/langtrain-ai/langtune},
312
+ year = {2025},
313
+ version = {0.1.0}
314
+ }
315
+ ```
316
+
317
+ ## Acknowledgements
318
+
319
+ We thank the following projects and communities:
320
+ - [PyTorch](https://pytorch.org/)
321
+ - [HuggingFace](https://huggingface.co/)
322
+ - [PEFT](https://github.com/huggingface/peft)
323
+
324
+ <p align="center">
325
+ <b>Made in India 🇮🇳 with ❤️ by the langtune team</b><br/>
326
+ <i>Star ⭐ this repo if you find it useful!</i>
327
+ </p>
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "langtune"
7
+ version = "0.0.2"
8
+ description = "A package for finetuning text models."
9
+ authors = [
10
+ { name = "Pritesh Raj", email = "priteshraj41@gmail.com" }
11
+ ]
12
+ readme = "README.md"
13
+ license = { file = "LICENSE" }
14
+ requires-python = ">=3.8"
15
+ dependencies = [
16
+ "torch>=1.10",
17
+ "numpy",
18
+ "tqdm",
19
+ "pyyaml",
20
+ "scipy"
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/langtrain-ai/langtune"
25
+ Documentation = "https://github.com/langtrain-ai/langtune/tree/main/docs"
26
+ Source = "https://github.com/langtrain-ai/langtune"
27
+ Tracker = "https://github.com/langtrain-ai/langtune/issues"
28
+
29
+ [project.scripts]
30
+ langtune-finetune = "langtune.cli.finetune:main"
31
+
32
+ [bumpver]
33
+ current_version = "0.1.0"
34
+ version_pattern = "MAJOR.MINOR.PATCH"
35
+ commit_message = "Bump version: {old_version} → {new_version}"
36
+ tag_message = "v{new_version}"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,368 @@
1
+ Metadata-Version: 2.4
2
+ Name: langtune
3
+ Version: 0.0.2
4
+ Summary: A package for finetuning text models.
5
+ Author-email: Pritesh Raj <priteshraj41@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Pritesh Raj
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/langtrain-ai/langtune
29
+ Project-URL: Documentation, https://github.com/langtrain-ai/langtune/tree/main/docs
30
+ Project-URL: Source, https://github.com/langtrain-ai/langtune
31
+ Project-URL: Tracker, https://github.com/langtrain-ai/langtune/issues
32
+ Requires-Python: >=3.8
33
+ Description-Content-Type: text/markdown
34
+ License-File: LICENSE
35
+ Requires-Dist: torch>=1.10
36
+ Requires-Dist: numpy
37
+ Requires-Dist: tqdm
38
+ Requires-Dist: pyyaml
39
+ Requires-Dist: scipy
40
+ Dynamic: license-file
41
+
42
+ # Langtune: Large Language Models (LLMs) with Efficient LoRA Fine-Tuning for Text
43
+
44
+ <hr/>
45
+ <p align="center">
46
+ <picture>
47
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/langtrain-ai/langtrain/main/static/langtune-use-dark.png">
48
+ <img alt="Langtune Logo" src="https://raw.githubusercontent.com/langtrain-ai/langtrain/main/static/langtune-white.png" width="full" />
49
+ </picture>
50
+ </p>
51
+
52
+ <!-- Badges -->
53
+ <p align="center">
54
+ <a href="https://pypi.org/project/langtune/"><img src="https://img.shields.io/pypi/v/langtune.svg" alt="PyPI version"></a>
55
+ <a href="https://pepy.tech/project/langtune"><img src="https://pepy.tech/badge/langtune" alt="Downloads"></a>
56
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License"></a>
57
+ <a href="https://img.shields.io/badge/coverage-90%25-brightgreen" alt="Coverage"> <img src="https://img.shields.io/badge/coverage-90%25-brightgreen"/></a>
58
+ <a href="https://img.shields.io/badge/python-3.8%2B-blue" alt="Python Version"> <img src="https://img.shields.io/badge/python-3.8%2B-blue"/></a>
59
+ <a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black"></a>
60
+ </p>
61
+
62
+ <p align="center">
63
+ <b>Langtune provides modular components for text models and LoRA-based fine-tuning.</b><br/>
64
+ <span style="font-size:1.1em"><i>Adapt and fine-tune language models for a range of NLP tasks.</i></span>
65
+ </p>
66
+ <hr/>
67
+
68
+ ## Quick Links
69
+ - [Documentation](docs/index.md)
70
+ - [Tutorials](docs/tutorials/index.md)
71
+ - [Changelog](CHANGELOG.md)
72
+ - [Contributing Guide](CONTRIBUTING.md)
73
+ - [Roadmap](ROADMAP.md)
74
+
75
+ ---
76
+
77
+ ## Table of Contents
78
+ - [Features](#features)
79
+ - [Showcase](#showcase)
80
+ - [Getting Started](#getting-started)
81
+ - [Supported Python Versions](#supported-python-versions)
82
+ - [Why langtune?](#why-langtune)
83
+ - [Architecture Overview](#architecture-overview)
84
+ - [Core Modules](#core-modules)
85
+ - [Performance & Efficiency](#performance--efficiency)
86
+ - [Advanced Configuration](#advanced-configuration)
87
+ - [Documentation & Resources](#documentation--resources)
88
+ - [Testing & Quality](#testing--quality)
89
+ - [Examples & Use Cases](#examples--use-cases)
90
+ - [Extending the Framework](#extending-the-framework)
91
+ - [Contributing](#contributing)
92
+ - [FAQ](#faq)
93
+ - [Citation](#citation)
94
+ - [Acknowledgements](#acknowledgements)
95
+ - [License](#license)
96
+
97
+ ---
98
+
99
+ ## Features
100
+ - LoRA adapters for parameter-efficient fine-tuning of LLMs
101
+ - Modular transformer backbone
102
+ - Model zoo for open-source language models
103
+ - Configurable and extensible codebase
104
+ - Checkpointing and resume support
105
+ - Mixed precision and distributed training
106
+ - Built-in metrics and visualization tools
107
+ - CLI for fine-tuning and evaluation
108
+ - Extensible callbacks (early stopping, logging, etc.)
109
+
110
+ ---
111
+
112
+ ## Showcase
113
+
114
+ Langtune is a framework for building and fine-tuning large language models with LoRA support. It is suitable for tasks such as text classification, summarization, question answering, and other NLP applications.
115
+
116
+ ---
117
+
118
+ ## Getting Started
119
+
120
+ Install with pip:
121
+
122
+ ```bash
123
+ pip install langtune
124
+ ```
125
+
126
+ Minimal example:
127
+
128
+ ```python
129
+ import torch
130
+ from langtune.models.llm import LanguageModel
131
+ from langtune.utils.config import default_config
132
+
133
+ input_ids = torch.randint(0, 1000, (2, 128))
134
+ model = LanguageModel(
135
+ vocab_size=default_config['vocab_size'],
136
+ embed_dim=default_config['embed_dim'],
137
+ num_layers=default_config['num_layers'],
138
+ num_heads=default_config['num_heads'],
139
+ mlp_ratio=default_config['mlp_ratio'],
140
+ lora_config=default_config['lora'],
141
+ )
142
+
143
+ with torch.no_grad():
144
+ out = model(input_ids)
145
+ print('Output shape:', out.shape)
146
+ ```
147
+
148
+ For more details, see the [Documentation](docs/index.md) and `src/langtune/cli/finetune.py`.
149
+
150
+ ---
151
+
152
+ ## Supported Python Versions
153
+ - Python 3.8+
154
+
155
+ ---
156
+
157
+ ## Why langtune?
158
+
159
+ - Parameter-efficient fine-tuning with LoRA adapters
160
+ - Modular transformer backbone for flexible model design
161
+ - Unified interface for open-source language models
162
+ - Designed for both research and production
163
+ - Efficient memory usage for large models
164
+
165
+ ---
166
+
167
+ ## Architecture Overview
168
+
169
+ Langtune uses a modular transformer backbone with LoRA adapters in attention and MLP layers. This allows adaptation of pre-trained models with fewer trainable parameters.
170
+
171
+ ### Model Data Flow
172
+
173
+ ```mermaid
174
+ ---
175
+ config:
176
+ layout: dagre
177
+ ---
178
+ flowchart TD
179
+ subgraph LoRA_Adapters["LoRA Adapters in Attention and MLP"]
180
+ LA1(["LoRA Adapter 1"])
181
+ LA2(["LoRA Adapter 2"])
182
+ LA3(["LoRA Adapter N"])
183
+ end
184
+ A(["Input Tokens"]) --> B(["Embedding Layer"])
185
+ B --> C(["Positional Encoding"])
186
+ C --> D1(["Encoder Layer 1"])
187
+ D1 --> D2(["Encoder Layer 2"])
188
+ D2 --> D3(["Encoder Layer N"])
189
+ D3 --> E(["LayerNorm"])
190
+ E --> F(["MLP Head"])
191
+ F --> G(["Output Logits"])
192
+ LA1 -.-> D1
193
+ LA2 -.-> D2
194
+ LA3 -.-> D3
195
+ LA1:::loraStyle
196
+ LA2:::loraStyle
197
+ LA3:::loraStyle
198
+ classDef loraStyle fill:#e1f5fe,stroke:#0277bd,stroke-width:2px
199
+ ```
200
+
201
+ ---
202
+
203
+ ## Core Modules
204
+
205
+ | Module | Description | Key Features |
206
+ |--------|-------------|--------------|
207
+ | Embedding | Token embedding and positional encoding | Configurable vocab size, position embeddings |
208
+ | TransformerEncoder | Multi-layer transformer backbone | Self-attention, LoRA integration, checkpointing |
209
+ | LoRALinear | Low-rank adaptation layers | Configurable rank, memory-efficient updates |
210
+ | MLPHead | Output projection layer | Classification, regression, dropout |
211
+ | Config System | Centralized configuration | YAML/JSON config, CLI overrides |
212
+ | Data Utils | Preprocessing and augmentation | Built-in tokenization, custom loaders |
213
+
214
+ ---
215
+
216
+ ## Performance & Efficiency
217
+
218
+ | Metric | Full Fine-tuning | LoRA Fine-tuning | Improvement |
219
+ |--------|------------------|------------------|-------------|
220
+ | Trainable Parameters | 125M | 3.2M | 97% reduction |
221
+ | Memory Usage | 16GB | 5GB | 69% reduction |
222
+ | Training Time | 6h | 2h | 67% faster |
223
+ | Storage per Task | 500MB | 12MB | 98% smaller |
224
+
225
+ *Benchmarks: Transformer-Base, WikiText-103, RTX 3090*
226
+
227
+ Supported model sizes: Transformer-Tiny, Transformer-Small, Transformer-Base, Transformer-Large
228
+
229
+ ---
230
+
231
+ ## Advanced Configuration
232
+
233
+ Example LoRA config:
234
+
235
+ ```python
236
+ lora_config = {
237
+ "rank": 16,
238
+ "alpha": 32,
239
+ "dropout": 0.1,
240
+ "target_modules": ["attention.qkv", "attention.proj", "mlp.fc1", "mlp.fc2"],
241
+ "merge_weights": False
242
+ }
243
+ ```
244
+
245
+ Example training config:
246
+
247
+ ```yaml
248
+ model:
249
+ name: "transformer_base"
250
+ vocab_size: 50257
251
+ embed_dim: 768
252
+ num_layers: 12
253
+ num_heads: 12
254
+ training:
255
+ epochs: 10
256
+ batch_size: 32
257
+ learning_rate: 1e-4
258
+ weight_decay: 0.01
259
+ warmup_steps: 1000
260
+ lora:
261
+ rank: 16
262
+ alpha: 32
263
+ dropout: 0.1
264
+ ```
265
+
266
+ ---
267
+
268
+ ## Documentation & Resources
269
+ - [API Reference](docs/api/index.md)
270
+ - [Tutorials and Examples](docs/tutorials/index.md)
271
+ - [Research Papers](#research-papers)
272
+ - [Best Practices Guide](docs/best_practices.md)
273
+ - [Troubleshooting](docs/troubleshooting.md)
274
+
275
+ ### Research Papers
276
+ - [LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685)
277
+ - [Attention Is All You Need](https://arxiv.org/abs/1706.03762)
278
+ - [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://arxiv.org/abs/1810.04805)
279
+
280
+ ---
281
+
282
+ ## Testing & Quality
283
+
284
+ Run tests:
285
+
286
+ ```bash
287
+ pytest tests/
288
+ ```
289
+
290
+ Code quality tools:
291
+
292
+ ```bash
293
+ flake8 src/
294
+ black src/ --check
295
+ mypy src/
296
+ bandit -r src/
297
+ ```
298
+
299
+ ---
300
+
301
+ ## Examples & Use Cases
302
+
303
+ Text classification:
304
+
305
+ ```python
306
+ from langtune import LanguageModel
307
+ from langtune.datasets import TextClassificationDataset
308
+
309
+ model = LanguageModel.from_pretrained("transformer_base")
310
+ dataset = TextClassificationDataset(train=True, tokenizer=model.tokenizer)
311
+ model.finetune(dataset, epochs=10, lora_rank=16)
312
+ ```
313
+
314
+ Custom dataset:
315
+
316
+ ```python
317
+ from langtune.datasets import CustomTextDataset
318
+
319
+ dataset = CustomTextDataset(
320
+ file_path="/path/to/dataset.txt",
321
+ split="train",
322
+ tokenizer=model.tokenizer
323
+ )
324
+ model.finetune(dataset, config_path="configs/custom_config.yaml")
325
+ ```
326
+
327
+ ---
328
+
329
+ ## Extending the Framework
330
+ - Add datasets in `src/langtune/data/datasets.py`
331
+ - Add callbacks in `src/langtune/callbacks/`
332
+ - Add models in `src/langtune/models/`
333
+ - Add CLI tools in `src/langtune/cli/`
334
+
335
+ ## Documentation
336
+ - See code comments and docstrings for details.
337
+ - For advanced usage, see `src/langtune/cli/finetune.py`.
338
+
339
+ ## Contributing
340
+ We welcome contributions. See the [Contributing Guide](CONTRIBUTING.md) for details.
341
+
342
+ ## License & Citation
343
+
344
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
345
+
346
+ If you use langtune in your research, please cite:
347
+
348
+ ```bibtex
349
+ @software{langtune2025,
350
+ author = {Pritesh Raj},
351
+ title = {langtune: LLMs with Efficient LoRA Fine-Tuning},
352
+ url = {https://github.com/langtrain-ai/langtune},
353
+ year = {2025},
354
+ version = {0.1.0}
355
+ }
356
+ ```
357
+
358
+ ## Acknowledgements
359
+
360
+ We thank the following projects and communities:
361
+ - [PyTorch](https://pytorch.org/)
362
+ - [HuggingFace](https://huggingface.co/)
363
+ - [PEFT](https://github.com/huggingface/peft)
364
+
365
+ <p align="center">
366
+ <b>Made in India 🇮🇳 with ❤️ by the langtune team</b><br/>
367
+ <i>Star ⭐ this repo if you find it useful!</i>
368
+ </p>
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/langtune/__init__.py
5
+ src/langtune.egg-info/PKG-INFO
6
+ src/langtune.egg-info/SOURCES.txt
7
+ src/langtune.egg-info/dependency_links.txt
8
+ src/langtune.egg-info/entry_points.txt
9
+ src/langtune.egg-info/requires.txt
10
+ src/langtune.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ langtune-finetune = langtune.cli.finetune:main
@@ -0,0 +1,5 @@
1
+ torch>=1.10
2
+ numpy
3
+ tqdm
4
+ pyyaml
5
+ scipy
@@ -0,0 +1 @@
1
+ langtune