langvision 0.0.1__tar.gz → 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 langvision might be problematic. Click here for more details.
- langvision-0.0.2/PKG-INFO +372 -0
- langvision-0.0.2/README.md +330 -0
- {langvision-0.0.1 → langvision-0.0.2}/pyproject.toml +2 -2
- langvision-0.0.2/src/langvision.egg-info/PKG-INFO +372 -0
- langvision-0.0.1/PKG-INFO +0 -463
- langvision-0.0.1/README.md +0 -421
- langvision-0.0.1/src/langvision.egg-info/PKG-INFO +0 -463
- {langvision-0.0.1 → langvision-0.0.2}/LICENSE +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/MANIFEST.in +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/docs/index.md +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/requirements.txt +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/setup.cfg +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/agents/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/callbacks/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/callbacks/base.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/callbacks/early_stopping.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/callbacks/logging.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/callbacks/registry.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/cli/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/cli/finetune.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/cli/train.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/components/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/components/attention.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/components/mlp.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/components/patch_embedding.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/config/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/data/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/data/datasets.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/example.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/filesystem/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/llm/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/memory/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/model_zoo.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/models/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/models/lora.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/models/vision_transformer.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/sync/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/telemetry/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/training/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/training/trainer.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/utils/__init__.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/utils/config.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/utils/cuda.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/utils/data.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision/utils/device.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision.egg-info/SOURCES.txt +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision.egg-info/dependency_links.txt +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision.egg-info/entry_points.txt +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision.egg-info/requires.txt +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/src/langvision.egg-info/top_level.txt +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/tests/test_example.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/tests/test_lora.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/tests/test_version.py +0 -0
- {langvision-0.0.1 → langvision-0.0.2}/tests/test_vision_transformer.py +0 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langvision
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A package for finetuning vision models.
|
|
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
|
+
# Langvision: Vision LLMs 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>Langvision provides modular components for vision models and LoRA-based fine-tuning.</b><br/>
|
|
65
|
+
<span style="font-size:1.1em"><i>Adapt and fine-tune vision models for a range of tasks.</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
|
+
- LoRA adapters for parameter-efficient fine-tuning
|
|
102
|
+
- Modular Vision Transformer (ViT) backbone
|
|
103
|
+
- Model zoo for open-source visual models
|
|
104
|
+
- Configurable and extensible codebase
|
|
105
|
+
- Checkpointing and resume support
|
|
106
|
+
- Mixed precision and distributed training
|
|
107
|
+
- Built-in metrics and visualization tools
|
|
108
|
+
- CLI for fine-tuning and evaluation
|
|
109
|
+
- Extensible callbacks (early stopping, logging, etc.)
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Showcase
|
|
114
|
+
|
|
115
|
+
Langvision is a framework for building and fine-tuning vision models with LoRA support. It is suitable for tasks such as image classification, visual question answering, and custom vision applications.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Getting Started
|
|
120
|
+
|
|
121
|
+
Install with pip:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pip install langvision
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Minimal example:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
import torch
|
|
131
|
+
from langvision.models.vision_transformer import VisionTransformer
|
|
132
|
+
from langvision.utils.config import default_config
|
|
133
|
+
|
|
134
|
+
x = torch.randn(2, 3, 224, 224)
|
|
135
|
+
model = VisionTransformer(
|
|
136
|
+
img_size=default_config['img_size'],
|
|
137
|
+
patch_size=default_config['patch_size'],
|
|
138
|
+
in_chans=default_config['in_chans'],
|
|
139
|
+
num_classes=default_config['num_classes'],
|
|
140
|
+
embed_dim=default_config['embed_dim'],
|
|
141
|
+
depth=default_config['depth'],
|
|
142
|
+
num_heads=default_config['num_heads'],
|
|
143
|
+
mlp_ratio=default_config['mlp_ratio'],
|
|
144
|
+
lora_config=default_config['lora'],
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
with torch.no_grad():
|
|
148
|
+
out = model(x)
|
|
149
|
+
print('Output shape:', out.shape)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
For more details, see the [Documentation](docs/index.md) and [src/langvision/cli/finetune.py](src/langvision/cli/finetune.py).
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Supported Python Versions
|
|
157
|
+
- Python 3.8+
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Why langvision?
|
|
162
|
+
|
|
163
|
+
- Parameter-efficient fine-tuning with LoRA adapters
|
|
164
|
+
- Modular ViT backbone for flexible model design
|
|
165
|
+
- Unified interface for open-source vision models
|
|
166
|
+
- Designed for both research and production
|
|
167
|
+
- Efficient memory usage for large models
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Architecture Overview
|
|
172
|
+
|
|
173
|
+
Langvision uses a modular Vision Transformer backbone with LoRA adapters in attention and MLP layers. This allows adaptation of pre-trained models with fewer trainable parameters.
|
|
174
|
+
|
|
175
|
+
### Model Data Flow
|
|
176
|
+
|
|
177
|
+
```mermaid
|
|
178
|
+
---
|
|
179
|
+
config:
|
|
180
|
+
layout: dagre
|
|
181
|
+
---
|
|
182
|
+
flowchart TD
|
|
183
|
+
subgraph LoRA_Adapters["LoRA Adapters in Attention and MLP"]
|
|
184
|
+
LA1(["LoRA Adapter 1"])
|
|
185
|
+
LA2(["LoRA Adapter 2"])
|
|
186
|
+
LA3(["LoRA Adapter N"])
|
|
187
|
+
end
|
|
188
|
+
A(["Input Image"]) --> B(["Patch Embedding"])
|
|
189
|
+
B --> C(["CLS Token & Positional Encoding"])
|
|
190
|
+
C --> D1(["Encoder Layer 1"])
|
|
191
|
+
D1 --> D2(["Encoder Layer 2"])
|
|
192
|
+
D2 --> D3(["Encoder Layer N"])
|
|
193
|
+
D3 --> E(["LayerNorm"])
|
|
194
|
+
E --> F(["MLP Head"])
|
|
195
|
+
F --> G(["Output Class Logits"])
|
|
196
|
+
LA1 -.-> D1
|
|
197
|
+
LA2 -.-> D2
|
|
198
|
+
LA3 -.-> D3
|
|
199
|
+
LA1:::loraStyle
|
|
200
|
+
LA2:::loraStyle
|
|
201
|
+
LA3:::loraStyle
|
|
202
|
+
classDef loraStyle fill:#e1f5fe,stroke:#0277bd,stroke-width:2px
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Core Modules
|
|
208
|
+
|
|
209
|
+
| Module | Description | Key Features |
|
|
210
|
+
|--------|-------------|--------------|
|
|
211
|
+
| PatchEmbedding | Image-to-patch conversion and embedding | Configurable patch sizes, position embeddings |
|
|
212
|
+
| TransformerEncoder | Multi-layer transformer backbone | Self-attention, LoRA integration, checkpointing |
|
|
213
|
+
| LoRALinear | Low-rank adaptation layers | Configurable rank, memory-efficient updates |
|
|
214
|
+
| MLPHead | Output projection layer | Classification, regression, dropout |
|
|
215
|
+
| Config System | Centralized configuration | YAML/JSON config, CLI overrides |
|
|
216
|
+
| Data Utils | Preprocessing and augmentation | Built-in transforms, custom loaders |
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Performance & Efficiency
|
|
221
|
+
|
|
222
|
+
| Metric | Full Fine-tuning | LoRA Fine-tuning | Improvement |
|
|
223
|
+
|--------|------------------|------------------|-------------|
|
|
224
|
+
| Trainable Parameters | 86M | 2.4M | 97% reduction |
|
|
225
|
+
| Memory Usage | 12GB | 4GB | 67% reduction |
|
|
226
|
+
| Training Time | 4h | 1.5h | 62% faster |
|
|
227
|
+
| Storage per Task | 344MB | 9.6MB | 97% smaller |
|
|
228
|
+
|
|
229
|
+
*Benchmarks: ViT-Base, CIFAR-100, RTX 3090*
|
|
230
|
+
|
|
231
|
+
Supported model sizes: ViT-Tiny, ViT-Small, ViT-Base, ViT-Large
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Advanced Configuration
|
|
236
|
+
|
|
237
|
+
Example LoRA config:
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
lora_config = {
|
|
241
|
+
"rank": 16,
|
|
242
|
+
"alpha": 32,
|
|
243
|
+
"dropout": 0.1,
|
|
244
|
+
"target_modules": ["attention.qkv", "attention.proj", "mlp.fc1", "mlp.fc2"],
|
|
245
|
+
"merge_weights": False
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Example training config:
|
|
250
|
+
|
|
251
|
+
```yaml
|
|
252
|
+
model:
|
|
253
|
+
name: "vit_base"
|
|
254
|
+
img_size: 224
|
|
255
|
+
patch_size: 16
|
|
256
|
+
num_classes: 1000
|
|
257
|
+
training:
|
|
258
|
+
epochs: 10
|
|
259
|
+
batch_size: 32
|
|
260
|
+
learning_rate: 1e-4
|
|
261
|
+
weight_decay: 0.01
|
|
262
|
+
warmup_steps: 1000
|
|
263
|
+
lora:
|
|
264
|
+
rank: 16
|
|
265
|
+
alpha: 32
|
|
266
|
+
dropout: 0.1
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Documentation & Resources
|
|
272
|
+
- [API Reference](docs/api/index.md)
|
|
273
|
+
- [Tutorials and Examples](docs/tutorials/index.md)
|
|
274
|
+
- [Research Papers](#research-papers)
|
|
275
|
+
- [Best Practices Guide](docs/best_practices.md)
|
|
276
|
+
- [Troubleshooting](docs/troubleshooting.md)
|
|
277
|
+
|
|
278
|
+
### Research Papers
|
|
279
|
+
- [LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685)
|
|
280
|
+
- [An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale](https://arxiv.org/abs/2010.11929)
|
|
281
|
+
- [Vision Transformer for Fine-Grained Image Classification](https://arxiv.org/abs/2103.07579)
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Testing & Quality
|
|
286
|
+
|
|
287
|
+
Run tests:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
pytest tests/
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Code quality tools:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
flake8 src/
|
|
297
|
+
black src/ --check
|
|
298
|
+
mypy src/
|
|
299
|
+
bandit -r src/
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Examples & Use Cases
|
|
305
|
+
|
|
306
|
+
Image classification:
|
|
307
|
+
|
|
308
|
+
```python
|
|
309
|
+
from langvision import VisionTransformer
|
|
310
|
+
from langvision.datasets import CIFAR10Dataset
|
|
311
|
+
|
|
312
|
+
model = VisionTransformer.from_pretrained("vit_base_patch16_224")
|
|
313
|
+
dataset = CIFAR10Dataset(train=True, transform=model.default_transform)
|
|
314
|
+
model.finetune(dataset, epochs=10, lora_rank=16)
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Custom dataset:
|
|
318
|
+
|
|
319
|
+
```python
|
|
320
|
+
from langvision.datasets import ImageFolderDataset
|
|
321
|
+
|
|
322
|
+
dataset = ImageFolderDataset(
|
|
323
|
+
root="/path/to/dataset",
|
|
324
|
+
split="train",
|
|
325
|
+
transform=model.default_transform
|
|
326
|
+
)
|
|
327
|
+
model.finetune(dataset, config_path="configs/custom_config.yaml")
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Extending the Framework
|
|
333
|
+
- Add datasets in `src/langvision/data/datasets.py`
|
|
334
|
+
- Add callbacks in `src/langvision/callbacks/`
|
|
335
|
+
- Add models in `src/langvision/models/`
|
|
336
|
+
- Add CLI tools in `src/langvision/cli/`
|
|
337
|
+
|
|
338
|
+
## Documentation
|
|
339
|
+
- See code comments and docstrings for details.
|
|
340
|
+
- For advanced usage, see `src/langvision/cli/finetune.py`.
|
|
341
|
+
|
|
342
|
+
## Contributing
|
|
343
|
+
We welcome contributions. See the [Contributing Guide](CONTRIBUTING.md) for details.
|
|
344
|
+
|
|
345
|
+
## License & Citation
|
|
346
|
+
|
|
347
|
+
This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
|
348
|
+
|
|
349
|
+
If you use langvision in your research, please cite:
|
|
350
|
+
|
|
351
|
+
```bibtex
|
|
352
|
+
@software{langtrain2025,
|
|
353
|
+
author = {Pritesh Raj},
|
|
354
|
+
title = {langtrain: Vision LLMs with Efficient LoRA Fine-Tuning},
|
|
355
|
+
url = {https://github.com/langtrain-ai/langvision},
|
|
356
|
+
year = {2025},
|
|
357
|
+
version = {1.0.0}
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
## Acknowledgements
|
|
362
|
+
|
|
363
|
+
We thank the following projects and communities:
|
|
364
|
+
- [PyTorch](https://pytorch.org/)
|
|
365
|
+
- [HuggingFace](https://huggingface.co/)
|
|
366
|
+
- [timm](https://github.com/rwightman/pytorch-image-models)
|
|
367
|
+
- [PEFT](https://github.com/huggingface/peft)
|
|
368
|
+
|
|
369
|
+
<p align="center">
|
|
370
|
+
<b>Made in India 🇮🇳 with ❤️ by the langtrain team</b><br/>
|
|
371
|
+
<i>Star ⭐ this repo if you find it useful!</i>
|
|
372
|
+
</p>
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
# Langvision: Vision LLMs with Efficient LoRA Fine-Tuning
|
|
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/langvision-use-dark.png">
|
|
7
|
+
<img alt="Langvision Logo" src="https://raw.githubusercontent.com/langtrain-ai/langtrain/main/static/langvision-white.png" width="full" />
|
|
8
|
+
</picture>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<!-- Badges -->
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="https://pypi.org/project/langvision/"><img src="https://img.shields.io/pypi/v/langvision.svg" alt="PyPI version"></a>
|
|
14
|
+
<a href="https://pepy.tech/project/langvision"><img src="https://pepy.tech/badge/langvision" 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>Langvision provides modular components for vision models and LoRA-based fine-tuning.</b><br/>
|
|
23
|
+
<span style="font-size:1.1em"><i>Adapt and fine-tune vision models for a range of 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 langvision?](#why-langvision)
|
|
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
|
|
60
|
+
- Modular Vision Transformer (ViT) backbone
|
|
61
|
+
- Model zoo for open-source visual 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
|
+
Langvision is a framework for building and fine-tuning vision models with LoRA support. It is suitable for tasks such as image classification, visual question answering, and custom vision applications.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Getting Started
|
|
78
|
+
|
|
79
|
+
Install with pip:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install langvision
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Minimal example:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import torch
|
|
89
|
+
from langvision.models.vision_transformer import VisionTransformer
|
|
90
|
+
from langvision.utils.config import default_config
|
|
91
|
+
|
|
92
|
+
x = torch.randn(2, 3, 224, 224)
|
|
93
|
+
model = VisionTransformer(
|
|
94
|
+
img_size=default_config['img_size'],
|
|
95
|
+
patch_size=default_config['patch_size'],
|
|
96
|
+
in_chans=default_config['in_chans'],
|
|
97
|
+
num_classes=default_config['num_classes'],
|
|
98
|
+
embed_dim=default_config['embed_dim'],
|
|
99
|
+
depth=default_config['depth'],
|
|
100
|
+
num_heads=default_config['num_heads'],
|
|
101
|
+
mlp_ratio=default_config['mlp_ratio'],
|
|
102
|
+
lora_config=default_config['lora'],
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
with torch.no_grad():
|
|
106
|
+
out = model(x)
|
|
107
|
+
print('Output shape:', out.shape)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
For more details, see the [Documentation](docs/index.md) and [src/langvision/cli/finetune.py](src/langvision/cli/finetune.py).
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Supported Python Versions
|
|
115
|
+
- Python 3.8+
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Why langvision?
|
|
120
|
+
|
|
121
|
+
- Parameter-efficient fine-tuning with LoRA adapters
|
|
122
|
+
- Modular ViT backbone for flexible model design
|
|
123
|
+
- Unified interface for open-source vision models
|
|
124
|
+
- Designed for both research and production
|
|
125
|
+
- Efficient memory usage for large models
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Architecture Overview
|
|
130
|
+
|
|
131
|
+
Langvision uses a modular Vision Transformer backbone with LoRA adapters in attention and MLP layers. This allows adaptation of pre-trained models with fewer trainable parameters.
|
|
132
|
+
|
|
133
|
+
### Model Data Flow
|
|
134
|
+
|
|
135
|
+
```mermaid
|
|
136
|
+
---
|
|
137
|
+
config:
|
|
138
|
+
layout: dagre
|
|
139
|
+
---
|
|
140
|
+
flowchart TD
|
|
141
|
+
subgraph LoRA_Adapters["LoRA Adapters in Attention and MLP"]
|
|
142
|
+
LA1(["LoRA Adapter 1"])
|
|
143
|
+
LA2(["LoRA Adapter 2"])
|
|
144
|
+
LA3(["LoRA Adapter N"])
|
|
145
|
+
end
|
|
146
|
+
A(["Input Image"]) --> B(["Patch Embedding"])
|
|
147
|
+
B --> C(["CLS Token & Positional Encoding"])
|
|
148
|
+
C --> D1(["Encoder Layer 1"])
|
|
149
|
+
D1 --> D2(["Encoder Layer 2"])
|
|
150
|
+
D2 --> D3(["Encoder Layer N"])
|
|
151
|
+
D3 --> E(["LayerNorm"])
|
|
152
|
+
E --> F(["MLP Head"])
|
|
153
|
+
F --> G(["Output Class Logits"])
|
|
154
|
+
LA1 -.-> D1
|
|
155
|
+
LA2 -.-> D2
|
|
156
|
+
LA3 -.-> D3
|
|
157
|
+
LA1:::loraStyle
|
|
158
|
+
LA2:::loraStyle
|
|
159
|
+
LA3:::loraStyle
|
|
160
|
+
classDef loraStyle fill:#e1f5fe,stroke:#0277bd,stroke-width:2px
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Core Modules
|
|
166
|
+
|
|
167
|
+
| Module | Description | Key Features |
|
|
168
|
+
|--------|-------------|--------------|
|
|
169
|
+
| PatchEmbedding | Image-to-patch conversion and embedding | Configurable patch sizes, position embeddings |
|
|
170
|
+
| TransformerEncoder | Multi-layer transformer backbone | Self-attention, LoRA integration, checkpointing |
|
|
171
|
+
| LoRALinear | Low-rank adaptation layers | Configurable rank, memory-efficient updates |
|
|
172
|
+
| MLPHead | Output projection layer | Classification, regression, dropout |
|
|
173
|
+
| Config System | Centralized configuration | YAML/JSON config, CLI overrides |
|
|
174
|
+
| Data Utils | Preprocessing and augmentation | Built-in transforms, custom loaders |
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Performance & Efficiency
|
|
179
|
+
|
|
180
|
+
| Metric | Full Fine-tuning | LoRA Fine-tuning | Improvement |
|
|
181
|
+
|--------|------------------|------------------|-------------|
|
|
182
|
+
| Trainable Parameters | 86M | 2.4M | 97% reduction |
|
|
183
|
+
| Memory Usage | 12GB | 4GB | 67% reduction |
|
|
184
|
+
| Training Time | 4h | 1.5h | 62% faster |
|
|
185
|
+
| Storage per Task | 344MB | 9.6MB | 97% smaller |
|
|
186
|
+
|
|
187
|
+
*Benchmarks: ViT-Base, CIFAR-100, RTX 3090*
|
|
188
|
+
|
|
189
|
+
Supported model sizes: ViT-Tiny, ViT-Small, ViT-Base, ViT-Large
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Advanced Configuration
|
|
194
|
+
|
|
195
|
+
Example LoRA config:
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
lora_config = {
|
|
199
|
+
"rank": 16,
|
|
200
|
+
"alpha": 32,
|
|
201
|
+
"dropout": 0.1,
|
|
202
|
+
"target_modules": ["attention.qkv", "attention.proj", "mlp.fc1", "mlp.fc2"],
|
|
203
|
+
"merge_weights": False
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Example training config:
|
|
208
|
+
|
|
209
|
+
```yaml
|
|
210
|
+
model:
|
|
211
|
+
name: "vit_base"
|
|
212
|
+
img_size: 224
|
|
213
|
+
patch_size: 16
|
|
214
|
+
num_classes: 1000
|
|
215
|
+
training:
|
|
216
|
+
epochs: 10
|
|
217
|
+
batch_size: 32
|
|
218
|
+
learning_rate: 1e-4
|
|
219
|
+
weight_decay: 0.01
|
|
220
|
+
warmup_steps: 1000
|
|
221
|
+
lora:
|
|
222
|
+
rank: 16
|
|
223
|
+
alpha: 32
|
|
224
|
+
dropout: 0.1
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Documentation & Resources
|
|
230
|
+
- [API Reference](docs/api/index.md)
|
|
231
|
+
- [Tutorials and Examples](docs/tutorials/index.md)
|
|
232
|
+
- [Research Papers](#research-papers)
|
|
233
|
+
- [Best Practices Guide](docs/best_practices.md)
|
|
234
|
+
- [Troubleshooting](docs/troubleshooting.md)
|
|
235
|
+
|
|
236
|
+
### Research Papers
|
|
237
|
+
- [LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685)
|
|
238
|
+
- [An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale](https://arxiv.org/abs/2010.11929)
|
|
239
|
+
- [Vision Transformer for Fine-Grained Image Classification](https://arxiv.org/abs/2103.07579)
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Testing & Quality
|
|
244
|
+
|
|
245
|
+
Run tests:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
pytest tests/
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Code quality tools:
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
flake8 src/
|
|
255
|
+
black src/ --check
|
|
256
|
+
mypy src/
|
|
257
|
+
bandit -r src/
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Examples & Use Cases
|
|
263
|
+
|
|
264
|
+
Image classification:
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
from langvision import VisionTransformer
|
|
268
|
+
from langvision.datasets import CIFAR10Dataset
|
|
269
|
+
|
|
270
|
+
model = VisionTransformer.from_pretrained("vit_base_patch16_224")
|
|
271
|
+
dataset = CIFAR10Dataset(train=True, transform=model.default_transform)
|
|
272
|
+
model.finetune(dataset, epochs=10, lora_rank=16)
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Custom dataset:
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
from langvision.datasets import ImageFolderDataset
|
|
279
|
+
|
|
280
|
+
dataset = ImageFolderDataset(
|
|
281
|
+
root="/path/to/dataset",
|
|
282
|
+
split="train",
|
|
283
|
+
transform=model.default_transform
|
|
284
|
+
)
|
|
285
|
+
model.finetune(dataset, config_path="configs/custom_config.yaml")
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## Extending the Framework
|
|
291
|
+
- Add datasets in `src/langvision/data/datasets.py`
|
|
292
|
+
- Add callbacks in `src/langvision/callbacks/`
|
|
293
|
+
- Add models in `src/langvision/models/`
|
|
294
|
+
- Add CLI tools in `src/langvision/cli/`
|
|
295
|
+
|
|
296
|
+
## Documentation
|
|
297
|
+
- See code comments and docstrings for details.
|
|
298
|
+
- For advanced usage, see `src/langvision/cli/finetune.py`.
|
|
299
|
+
|
|
300
|
+
## Contributing
|
|
301
|
+
We welcome contributions. See the [Contributing Guide](CONTRIBUTING.md) for details.
|
|
302
|
+
|
|
303
|
+
## License & Citation
|
|
304
|
+
|
|
305
|
+
This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
|
306
|
+
|
|
307
|
+
If you use langvision in your research, please cite:
|
|
308
|
+
|
|
309
|
+
```bibtex
|
|
310
|
+
@software{langtrain2025,
|
|
311
|
+
author = {Pritesh Raj},
|
|
312
|
+
title = {langtrain: Vision LLMs with Efficient LoRA Fine-Tuning},
|
|
313
|
+
url = {https://github.com/langtrain-ai/langvision},
|
|
314
|
+
year = {2025},
|
|
315
|
+
version = {1.0.0}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Acknowledgements
|
|
320
|
+
|
|
321
|
+
We thank the following projects and communities:
|
|
322
|
+
- [PyTorch](https://pytorch.org/)
|
|
323
|
+
- [HuggingFace](https://huggingface.co/)
|
|
324
|
+
- [timm](https://github.com/rwightman/pytorch-image-models)
|
|
325
|
+
- [PEFT](https://github.com/huggingface/peft)
|
|
326
|
+
|
|
327
|
+
<p align="center">
|
|
328
|
+
<b>Made in India 🇮🇳 with ❤️ by the langtrain team</b><br/>
|
|
329
|
+
<i>Star ⭐ this repo if you find it useful!</i>
|
|
330
|
+
</p>
|
|
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "langvision"
|
|
7
|
-
version = "0.0.
|
|
8
|
-
description = "
|
|
7
|
+
version = "0.0.2"
|
|
8
|
+
description = "A package for finetuning vision models."
|
|
9
9
|
authors = [
|
|
10
10
|
{ name = "Pritesh Raj", email = "priteshraj10@gmail.com" }
|
|
11
11
|
]
|