langvision 0.0.1__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 langvision might be problematic. Click here for more details.
- langvision-0.0.1/LICENSE +21 -0
- langvision-0.0.1/MANIFEST.in +4 -0
- langvision-0.0.1/PKG-INFO +463 -0
- langvision-0.0.1/README.md +421 -0
- langvision-0.0.1/docs/index.md +12 -0
- langvision-0.0.1/pyproject.toml +38 -0
- langvision-0.0.1/requirements.txt +5 -0
- langvision-0.0.1/setup.cfg +4 -0
- langvision-0.0.1/src/langvision/__init__.py +7 -0
- langvision-0.0.1/src/langvision/agents/__init__.py +8 -0
- langvision-0.0.1/src/langvision/callbacks/__init__.py +0 -0
- langvision-0.0.1/src/langvision/callbacks/base.py +11 -0
- langvision-0.0.1/src/langvision/callbacks/early_stopping.py +16 -0
- langvision-0.0.1/src/langvision/callbacks/logging.py +17 -0
- langvision-0.0.1/src/langvision/callbacks/registry.py +10 -0
- langvision-0.0.1/src/langvision/cli/__init__.py +0 -0
- langvision-0.0.1/src/langvision/cli/finetune.py +181 -0
- langvision-0.0.1/src/langvision/cli/train.py +101 -0
- langvision-0.0.1/src/langvision/components/__init__.py +1 -0
- langvision-0.0.1/src/langvision/components/attention.py +58 -0
- langvision-0.0.1/src/langvision/components/mlp.py +10 -0
- langvision-0.0.1/src/langvision/components/patch_embedding.py +15 -0
- langvision-0.0.1/src/langvision/config/__init__.py +14 -0
- langvision-0.0.1/src/langvision/data/__init__.py +0 -0
- langvision-0.0.1/src/langvision/data/datasets.py +21 -0
- langvision-0.0.1/src/langvision/example.py +5 -0
- langvision-0.0.1/src/langvision/filesystem/__init__.py +15 -0
- langvision-0.0.1/src/langvision/llm/__init__.py +5 -0
- langvision-0.0.1/src/langvision/memory/__init__.py +21 -0
- langvision-0.0.1/src/langvision/model_zoo.py +2 -0
- langvision-0.0.1/src/langvision/models/__init__.py +1 -0
- langvision-0.0.1/src/langvision/models/lora.py +30 -0
- langvision-0.0.1/src/langvision/models/vision_transformer.py +28 -0
- langvision-0.0.1/src/langvision/sync/__init__.py +16 -0
- langvision-0.0.1/src/langvision/telemetry/__init__.py +9 -0
- langvision-0.0.1/src/langvision/training/__init__.py +0 -0
- langvision-0.0.1/src/langvision/training/trainer.py +100 -0
- langvision-0.0.1/src/langvision/utils/__init__.py +25 -0
- langvision-0.0.1/src/langvision/utils/config.py +15 -0
- langvision-0.0.1/src/langvision/utils/cuda.py +26 -0
- langvision-0.0.1/src/langvision/utils/data.py +8 -0
- langvision-0.0.1/src/langvision/utils/device.py +20 -0
- langvision-0.0.1/src/langvision.egg-info/PKG-INFO +463 -0
- langvision-0.0.1/src/langvision.egg-info/SOURCES.txt +50 -0
- langvision-0.0.1/src/langvision.egg-info/dependency_links.txt +1 -0
- langvision-0.0.1/src/langvision.egg-info/entry_points.txt +2 -0
- langvision-0.0.1/src/langvision.egg-info/requires.txt +7 -0
- langvision-0.0.1/src/langvision.egg-info/top_level.txt +1 -0
- langvision-0.0.1/tests/test_example.py +10 -0
- langvision-0.0.1/tests/test_lora.py +9 -0
- langvision-0.0.1/tests/test_version.py +17 -0
- langvision-0.0.1/tests/test_vision_transformer.py +19 -0
langvision-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Plim
|
|
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,463 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langvision
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Vision LLMs with Efficient LoRA Fine-Tuning
|
|
5
|
+
Author-email: Pritesh Raj <priteshraj10@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Plim
|
|
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
|
+
Project-URL: Homepage, https://github.com/langtrain-ai/langtrain
|
|
28
|
+
Project-URL: Documentation, https://github.com/langtrain-ai/langtrain/tree/main/docs
|
|
29
|
+
Project-URL: Source, https://github.com/langtrain-ai/langtrain
|
|
30
|
+
Project-URL: Tracker, https://github.com/langtrain-ai/langtrain/issues
|
|
31
|
+
Requires-Python: >=3.8
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Requires-Dist: torch>=1.10
|
|
35
|
+
Requires-Dist: numpy
|
|
36
|
+
Requires-Dist: tqdm
|
|
37
|
+
Requires-Dist: pyyaml
|
|
38
|
+
Requires-Dist: scipy
|
|
39
|
+
Requires-Dist: matplotlib
|
|
40
|
+
Requires-Dist: pillow
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# langtrain: Vision LLMs (Large Language Models for Vision) with Efficient LoRA Fine-Tuning
|
|
44
|
+
|
|
45
|
+
<hr/>
|
|
46
|
+
<p align="center">
|
|
47
|
+
<picture>
|
|
48
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/langtrain-ai/langtrain/main/static/langvision-use-dark.png">
|
|
49
|
+
<img alt="Langvision Logo" src="https://raw.githubusercontent.com/langtrain-ai/langtrain/main/static/langvision-white.png" width="full" />
|
|
50
|
+
</picture>
|
|
51
|
+
</p>
|
|
52
|
+
|
|
53
|
+
<!-- Badges -->
|
|
54
|
+
<p align="center">
|
|
55
|
+
<a href="https://pypi.org/project/langvision/"><img src="https://img.shields.io/pypi/v/langvision.svg" alt="PyPI version"></a>
|
|
56
|
+
<a href="https://pepy.tech/project/langvision"><img src="https://pepy.tech/badge/langvision" alt="Downloads"></a>
|
|
57
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License"></a>
|
|
58
|
+
<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>
|
|
59
|
+
<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>
|
|
60
|
+
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black"></a>
|
|
61
|
+
</p>
|
|
62
|
+
|
|
63
|
+
<p align="center">
|
|
64
|
+
<b>Modular Vision LLMs (Large Language Models for Vision) with Efficient LoRA Fine-Tuning</b><br/>
|
|
65
|
+
<span style="font-size:1.1em"><i>Build, adapt, and fine-tune vision models with ease and efficiency.</i></span>
|
|
66
|
+
</p>
|
|
67
|
+
<hr/>
|
|
68
|
+
|
|
69
|
+
## ๐ Quick Links
|
|
70
|
+
- [Documentation](docs/index.md)
|
|
71
|
+
- [Tutorials](docs/tutorials/index.md)
|
|
72
|
+
- [Changelog](CHANGELOG.md)
|
|
73
|
+
- [Contributing Guide](CONTRIBUTING.md)
|
|
74
|
+
- [Roadmap](ROADMAP.md)
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## ๐ Table of Contents
|
|
79
|
+
- [Features](#-features)
|
|
80
|
+
- [Showcase](#-showcase)
|
|
81
|
+
- [Getting Started](#-getting-started)
|
|
82
|
+
- [Supported Python Versions](#-supported-python-versions)
|
|
83
|
+
- [Why langvision?](#-why-langvision)
|
|
84
|
+
- [Architecture Overview](#-architecture-overview)
|
|
85
|
+
- [Core Modules](#-core-modules)
|
|
86
|
+
- [Performance & Efficiency](#-performance--efficiency)
|
|
87
|
+
- [Advanced Configuration](#-advanced-configuration)
|
|
88
|
+
- [Documentation & Resources](#-documentation--resources)
|
|
89
|
+
- [Testing & Quality](#-testing--quality)
|
|
90
|
+
- [Examples & Use Cases](#-examples--use-cases)
|
|
91
|
+
- [Extending the Framework](#-extending-the-framework)
|
|
92
|
+
- [Contributing](#-contributing)
|
|
93
|
+
- [FAQ](#-faq)
|
|
94
|
+
- [Citation](#-citation)
|
|
95
|
+
- [Acknowledgements](#-acknowledgements)
|
|
96
|
+
- [License](#-license)
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## โจ Features
|
|
101
|
+
- ๐ง **Plug-and-play LoRA adapters** for parameter-efficient fine-tuning
|
|
102
|
+
- ๐๏ธ **Modular Vision Transformer (ViT) backbone** with customizable components
|
|
103
|
+
- ๐ฏ **Unified model zoo** for open-source visual models
|
|
104
|
+
- โ๏ธ **Easy configuration** and extensible codebase
|
|
105
|
+
- ๐ **Production ready** with comprehensive testing and documentation
|
|
106
|
+
- ๐พ **Memory efficient** training with gradient checkpointing support
|
|
107
|
+
- ๐ **Built-in metrics** and visualization tools
|
|
108
|
+
- ๐งฉ **Modular training loop** with LoRA support
|
|
109
|
+
- ๐ฏ **Unified CLI** for fine-tuning and evaluation
|
|
110
|
+
- ๐ **Extensible callbacks** (early stopping, logging, etc.)
|
|
111
|
+
- ๐ฆ **Checkpointing and resume**
|
|
112
|
+
- ๐ **Mixed precision training**
|
|
113
|
+
- ๐ง **Easy dataset and model extension**
|
|
114
|
+
- โก **Ready for distributed/multi-GPU training**
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## ๐ Showcase
|
|
119
|
+
|
|
120
|
+
**langvision** is a modular, research-friendly framework for building and fine-tuning Vision Large Language Models (LLMs) with efficient Low-Rank Adaptation (LoRA) support. Whether you're working on image classification, visual question answering, or custom vision tasks, langvision provides the tools you need for parameter-efficient model adaptation.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## ๐ Getting Started
|
|
125
|
+
|
|
126
|
+
Here's a minimal example to get you up and running:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pip install langvision
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
import torch
|
|
134
|
+
from langvision.models.vision_transformer import VisionTransformer
|
|
135
|
+
from langvision.utils.config import default_config
|
|
136
|
+
|
|
137
|
+
# Create model
|
|
138
|
+
x = torch.randn(2, 3, 224, 224)
|
|
139
|
+
model = VisionTransformer(
|
|
140
|
+
img_size=default_config['img_size'],
|
|
141
|
+
patch_size=default_config['patch_size'],
|
|
142
|
+
in_chans=default_config['in_chans'],
|
|
143
|
+
num_classes=default_config['num_classes'],
|
|
144
|
+
embed_dim=default_config['embed_dim'],
|
|
145
|
+
depth=default_config['depth'],
|
|
146
|
+
num_heads=default_config['num_heads'],
|
|
147
|
+
mlp_ratio=default_config['mlp_ratio'],
|
|
148
|
+
lora_config=default_config['lora'],
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
# Forward pass
|
|
152
|
+
with torch.no_grad():
|
|
153
|
+
out = model(x)
|
|
154
|
+
print('Output shape:', out.shape)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
For advanced usage, CLI details, and more, see the [Documentation](docs/index.md) and [src/langvision/cli/finetune.py](src/langvision/cli/finetune.py).
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## ๐ Supported Python Versions
|
|
162
|
+
- Python 3.8+
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## ๐งฉ Why langvision?
|
|
167
|
+
|
|
168
|
+
- **Parameter-efficient fine-tuning**: Plug-and-play LoRA adapters for fast, memory-efficient adaptation with minimal computational overhead
|
|
169
|
+
- **Modular ViT backbone**: Swap or extend components like patch embedding, attention, or MLP heads with ease
|
|
170
|
+
- **Unified model zoo**: Access and experiment with open-source visual models through a consistent interface
|
|
171
|
+
- **Research & production ready**: Clean, extensible codebase with comprehensive configuration options and robust utilities
|
|
172
|
+
- **Memory efficient**: Fine-tune large models on consumer hardware by updating only a small fraction of parameters
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## ๐๏ธ Architecture Overview
|
|
177
|
+
|
|
178
|
+
langvision is built around a modular Vision Transformer (ViT) backbone, with LoRA adapters strategically injected into attention and MLP layers for efficient fine-tuning. This approach allows you to adapt large pre-trained models using only a fraction of the original parameters.
|
|
179
|
+
|
|
180
|
+
### Model Data Flow
|
|
181
|
+
|
|
182
|
+
```mermaid
|
|
183
|
+
---
|
|
184
|
+
config:
|
|
185
|
+
layout: dagre
|
|
186
|
+
---
|
|
187
|
+
flowchart TD
|
|
188
|
+
subgraph LoRA_Adapters["LoRA Adapters in Attention and MLP"]
|
|
189
|
+
LA1(["LoRA Adapter 1"])
|
|
190
|
+
LA2(["LoRA Adapter 2"])
|
|
191
|
+
LA3(["LoRA Adapter N"])
|
|
192
|
+
end
|
|
193
|
+
A(["Input Image"]) --> B(["Patch Embedding"])
|
|
194
|
+
B --> C(["CLS Token & Positional Encoding"])
|
|
195
|
+
C --> D1(["Encoder Layer 1"])
|
|
196
|
+
D1 --> D2(["Encoder Layer 2"])
|
|
197
|
+
D2 --> D3(["Encoder Layer N"])
|
|
198
|
+
D3 --> E(["LayerNorm"])
|
|
199
|
+
E --> F(["MLP Head"])
|
|
200
|
+
F --> G(["Output Class Logits"])
|
|
201
|
+
LA1 -.-> D1
|
|
202
|
+
LA2 -.-> D2
|
|
203
|
+
LA3 -.-> D3
|
|
204
|
+
LA1:::loraStyle
|
|
205
|
+
LA2:::loraStyle
|
|
206
|
+
LA3:::loraStyle
|
|
207
|
+
classDef loraStyle fill:#e1f5fe,stroke:#0277bd,stroke-width:2px
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Architecture Components
|
|
211
|
+
|
|
212
|
+
**Legend:**
|
|
213
|
+
- **Solid arrows**: Main data flow through the Vision Transformer
|
|
214
|
+
- **Dashed arrows**: LoRA adapter injection points in encoder layers
|
|
215
|
+
- **Blue boxes**: LoRA adapters for parameter-efficient fine-tuning
|
|
216
|
+
|
|
217
|
+
**Data Flow Steps:**
|
|
218
|
+
1. **Input Image** (224ร224ร3): Raw image data ready for processing
|
|
219
|
+
2. **Patch Embedding**: Image split into 16ร16 patches and projected to embedding dimension
|
|
220
|
+
3. **CLS Token & Positional Encoding**: Classification token prepended with learnable position embeddings
|
|
221
|
+
4. **Transformer Encoder Stack**: Multi-layer transformer with self-attention and MLP blocks
|
|
222
|
+
- **LoRA Integration**: Low-rank adapters injected into attention and MLP layers
|
|
223
|
+
- **Efficient Updates**: Only LoRA parameters updated during fine-tuning
|
|
224
|
+
5. **LayerNorm**: Final normalization of encoder outputs
|
|
225
|
+
6. **MLP Head**: Task-specific classification or regression head
|
|
226
|
+
7. **Output**: Final predictions (class probabilities, regression values, etc.)
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## ๐งฉ Core Modules
|
|
231
|
+
|
|
232
|
+
| Module | Description | Key Features |
|
|
233
|
+
|--------|-------------|--------------|
|
|
234
|
+
| **PatchEmbedding** | Image-to-patch conversion and embedding | โข Configurable patch sizes<br>โข Learnable position embeddings<br>โข Support for different input resolutions |
|
|
235
|
+
| **TransformerEncoder** | Multi-layer transformer backbone | โข Self-attention mechanisms<br>โข LoRA adapter integration<br>โข Gradient checkpointing support |
|
|
236
|
+
| **LoRALinear** | Low-rank adaptation layers | โข Configurable rank and scaling<br>โข Memory-efficient updates<br>โข Easy enable/disable functionality |
|
|
237
|
+
| **MLPHead** | Output projection layer | โข Multi-class classification<br>โข Regression support<br>โข Dropout regularization |
|
|
238
|
+
| **Config System** | Centralized configuration management | โข YAML/JSON config files<br>โข Command-line overrides<br>โข Validation and defaults |
|
|
239
|
+
| **Data Utils** | Preprocessing and augmentation | โข Built-in transforms<br>โข Custom dataset loaders<br>โข Efficient data pipelines |
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## ๐ Performance & Efficiency
|
|
244
|
+
|
|
245
|
+
### LoRA Benefits
|
|
246
|
+
|
|
247
|
+
| Metric | Full Fine-tuning | LoRA Fine-tuning | Improvement |
|
|
248
|
+
|--------|------------------|------------------|-------------|
|
|
249
|
+
| **Trainable Parameters** | 86M | 2.4M | **97% reduction** |
|
|
250
|
+
| **Memory Usage** | 12GB | 4GB | **67% reduction** |
|
|
251
|
+
| **Training Time** | 4 hours | 1.5 hours | **62% faster** |
|
|
252
|
+
| **Storage per Task** | 344MB | 9.6MB | **97% smaller** |
|
|
253
|
+
|
|
254
|
+
*Benchmarks on ViT-Base with CIFAR-100, RTX 3090*
|
|
255
|
+
|
|
256
|
+
### Supported Model Sizes
|
|
257
|
+
|
|
258
|
+
- **ViT-Tiny**: 5.7M parameters, perfect for experimentation
|
|
259
|
+
- **ViT-Small**: 22M parameters, good balance of performance and efficiency
|
|
260
|
+
- **ViT-Base**: 86M parameters, strong performance across tasks
|
|
261
|
+
- **ViT-Large**: 307M parameters, state-of-the-art results
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## ๐ง Advanced Configuration
|
|
266
|
+
|
|
267
|
+
### LoRA Configuration
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
lora_config = {
|
|
271
|
+
"rank": 16, # Low-rank dimension
|
|
272
|
+
"alpha": 32, # Scaling factor
|
|
273
|
+
"dropout": 0.1, # Dropout rate
|
|
274
|
+
"target_modules": [ # Modules to adapt
|
|
275
|
+
"attention.qkv",
|
|
276
|
+
"attention.proj",
|
|
277
|
+
"mlp.fc1",
|
|
278
|
+
"mlp.fc2"
|
|
279
|
+
],
|
|
280
|
+
"merge_weights": False # Whether to merge during inference
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Training Configuration
|
|
285
|
+
|
|
286
|
+
```yaml
|
|
287
|
+
# config.yaml
|
|
288
|
+
model:
|
|
289
|
+
name: "vit_base"
|
|
290
|
+
img_size: 224
|
|
291
|
+
patch_size: 16
|
|
292
|
+
num_classes: 1000
|
|
293
|
+
|
|
294
|
+
training:
|
|
295
|
+
epochs: 10
|
|
296
|
+
batch_size: 32
|
|
297
|
+
learning_rate: 1e-4
|
|
298
|
+
weight_decay: 0.01
|
|
299
|
+
warmup_steps: 1000
|
|
300
|
+
|
|
301
|
+
lora:
|
|
302
|
+
rank: 16
|
|
303
|
+
alpha: 32
|
|
304
|
+
dropout: 0.1
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## ๐ Documentation & Resources
|
|
310
|
+
|
|
311
|
+
- ๐ [Complete API Reference](docs/api/index.md)
|
|
312
|
+
- ๐ [Tutorials and Examples](docs/tutorials/index.md)
|
|
313
|
+
- ๐ฌ [Research Papers](#research-papers)
|
|
314
|
+
- ๐ก [Best Practices Guide](docs/best_practices.md)
|
|
315
|
+
- ๐ [Troubleshooting](docs/troubleshooting.md)
|
|
316
|
+
|
|
317
|
+
### Research Papers
|
|
318
|
+
- [LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685)
|
|
319
|
+
- [An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale](https://arxiv.org/abs/2010.11929)
|
|
320
|
+
- [Vision Transformer for Fine-Grained Image Classification](https://arxiv.org/abs/2103.07579)
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## ๐งช Testing & Quality
|
|
325
|
+
|
|
326
|
+
Run the comprehensive test suite:
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
# Unit tests
|
|
330
|
+
pytest tests/unit/
|
|
331
|
+
|
|
332
|
+
# Integration tests
|
|
333
|
+
pytest tests/integration/
|
|
334
|
+
|
|
335
|
+
# Performance benchmarks
|
|
336
|
+
pytest tests/benchmarks/
|
|
337
|
+
|
|
338
|
+
# All tests with coverage
|
|
339
|
+
pytest tests/ --cov=langvision --cov-report=html
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Code Quality Tools
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
# Linting
|
|
346
|
+
flake8 src/
|
|
347
|
+
black src/ --check
|
|
348
|
+
|
|
349
|
+
# Type checking
|
|
350
|
+
mypy src/
|
|
351
|
+
|
|
352
|
+
# Security scanning
|
|
353
|
+
bandit -r src/
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## ๐ Examples & Use Cases
|
|
359
|
+
|
|
360
|
+
### Image Classification
|
|
361
|
+
```python
|
|
362
|
+
from langvision import VisionTransformer
|
|
363
|
+
from langvision.datasets import CIFAR10Dataset
|
|
364
|
+
|
|
365
|
+
# Load pre-trained model
|
|
366
|
+
model = VisionTransformer.from_pretrained("vit_base_patch16_224")
|
|
367
|
+
|
|
368
|
+
# Fine-tune on CIFAR-10
|
|
369
|
+
dataset = CIFAR10Dataset(train=True, transform=model.default_transform)
|
|
370
|
+
model.finetune(dataset, epochs=10, lora_rank=16)
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Custom Dataset
|
|
374
|
+
```python
|
|
375
|
+
from langvision.datasets import ImageFolderDataset
|
|
376
|
+
|
|
377
|
+
# Your custom dataset
|
|
378
|
+
dataset = ImageFolderDataset(
|
|
379
|
+
root="/path/to/dataset",
|
|
380
|
+
split="train",
|
|
381
|
+
transform=model.default_transform
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
# Fine-tune with custom configuration
|
|
385
|
+
model.finetune(
|
|
386
|
+
dataset,
|
|
387
|
+
config_path="configs/custom_config.yaml"
|
|
388
|
+
)
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## ๐งฉ Extending the Framework
|
|
394
|
+
- Add new datasets in `src/langvision/data/datasets.py`
|
|
395
|
+
- Add new callbacks in `src/langvision/callbacks/`
|
|
396
|
+
- Add new models in `src/langvision/models/`
|
|
397
|
+
- Add new CLI tools in `src/langvision/cli/`
|
|
398
|
+
|
|
399
|
+
## ๐ Documentation
|
|
400
|
+
- See code comments and docstrings for details on each module.
|
|
401
|
+
- For advanced usage, see the `src/langvision/cli/finetune.py` script.
|
|
402
|
+
|
|
403
|
+
## ๐ค Contributing
|
|
404
|
+
We welcome contributions from the community! Here's how you can get involved:
|
|
405
|
+
|
|
406
|
+
### Ways to Contribute
|
|
407
|
+
- ๐ **Report bugs** by opening issues with detailed reproduction steps
|
|
408
|
+
- ๐ก **Suggest features** through feature requests and discussions
|
|
409
|
+
- ๐ **Improve documentation** with examples, tutorials, and API docs
|
|
410
|
+
- ๐ง **Submit pull requests** for bug fixes and new features
|
|
411
|
+
- ๐งช **Add tests** to improve code coverage and reliability
|
|
412
|
+
|
|
413
|
+
### Development Setup
|
|
414
|
+
```bash
|
|
415
|
+
# Clone and setup development environment
|
|
416
|
+
git clone https://github.com/langtrain-ai/langvision.git
|
|
417
|
+
cd langvision
|
|
418
|
+
pip install -e ".[dev]"
|
|
419
|
+
|
|
420
|
+
# Install pre-commit hooks
|
|
421
|
+
pre-commit install
|
|
422
|
+
|
|
423
|
+
# Run tests
|
|
424
|
+
pytest tests/
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Community Resources
|
|
428
|
+
- ๐ฌ [GitHub Discussions](https://github.com/langtrain-ai/langvision/discussions) - Ask questions and share ideas
|
|
429
|
+
- ๐ [Issue Tracker](https://github.com/langtrain-ai/langvision/issues) - Report bugs and request features
|
|
430
|
+
- ๐ [Contributing Guide](CONTRIBUTING.md) - Detailed contribution guidelines
|
|
431
|
+
- ๐ฏ [Roadmap](ROADMAP.md) - See what's planned for future releases
|
|
432
|
+
|
|
433
|
+
## ๐ License & Citation
|
|
434
|
+
|
|
435
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
436
|
+
|
|
437
|
+
### Citation
|
|
438
|
+
|
|
439
|
+
If you use langtrain in your research, please cite:
|
|
440
|
+
|
|
441
|
+
```bibtex
|
|
442
|
+
@software{langtrain2025,
|
|
443
|
+
author = {Pritesh Raj},
|
|
444
|
+
title = {langtrain: Vision LLMs with Efficient LoRA Fine-Tuning},
|
|
445
|
+
url = {https://github.com/langtrain-ai/langvision},
|
|
446
|
+
year = {2025},
|
|
447
|
+
version = {1.0.0}
|
|
448
|
+
}
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
## ๐ Acknowledgements
|
|
452
|
+
|
|
453
|
+
We thank the following projects and communities:
|
|
454
|
+
|
|
455
|
+
- [PyTorch](https://pytorch.org/) - Deep learning framework
|
|
456
|
+
- [HuggingFace](https://huggingface.co/) - Transformers and model hub
|
|
457
|
+
- [timm](https://github.com/rwightman/pytorch-image-models) - Vision model implementations
|
|
458
|
+
- [PEFT](https://github.com/huggingface/peft) - Parameter-efficient fine-tuning methods
|
|
459
|
+
|
|
460
|
+
<p align="center">
|
|
461
|
+
<b>Made in India ๐ฎ๐ณ with โค๏ธ by the langtrain team</b><br/>
|
|
462
|
+
<i>Star โญ this repo if you find it useful!</i>
|
|
463
|
+
</p>
|