langtune 0.0.2__py3-none-any.whl

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/__init__.py ADDED
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,7 @@
1
+ langtune/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ langtune-0.0.2.dist-info/licenses/LICENSE,sha256=OtXSlJyUGegIJFsZKNIhua8XYZ2tOgxNP1DYa9Hbgns,1068
3
+ langtune-0.0.2.dist-info/METADATA,sha256=e-pK5qp4pXXvPp-zq5KaoT8b3GMTuGJBD-jULopsf54,11026
4
+ langtune-0.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ langtune-0.0.2.dist-info/entry_points.txt,sha256=kjkeBLj0Lh5j7cMkm7_f8v4BpVpJDir7_zPh-KJgGcA,65
6
+ langtune-0.0.2.dist-info/top_level.txt,sha256=R0BPR95TtWx__rtQReaNmb4dbyGx0q2AypdeQYzxj7s,9
7
+ langtune-0.0.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ langtune-finetune = langtune.cli.finetune:main
@@ -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 @@
1
+ langtune