Metadata-Version: 2.4
Name: langtune
Version: 0.1.12
Summary: Efficient LoRA Fine-Tuning for Large Language Models - Train smarter, not harder.
Author-email: Pritesh Raj <priteshraj41@gmail.com>
Maintainer-email: Langtrain AI <contact@langtrain.ai>
License: MIT License
        
        Copyright (c) 2025 Pritesh Raj
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/langtrain-ai/langtune
Project-URL: Documentation, https://github.com/langtrain-ai/langtune/tree/main/docs
Project-URL: Repository, https://github.com/langtrain-ai/langtune
Project-URL: Changelog, https://github.com/langtrain-ai/langtune/blob/main/CHANGELOG.md
Project-URL: Bug Tracker, https://github.com/langtrain-ai/langtune/issues
Keywords: llm,lora,fine-tuning,machine-learning,deep-learning,transformers,nlp,language-model,pytorch,rlhf,dpo,ppo
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=1.10
Requires-Dist: numpy
Requires-Dist: tqdm
Requires-Dist: pyyaml
Requires-Dist: scipy
Requires-Dist: wandb
Requires-Dist: rich>=13.0.0
Requires-Dist: rich>=13.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: isort; extra == "dev"
Provides-Extra: all
Requires-Dist: transformers; extra == "all"
Requires-Dist: datasets; extra == "all"
Requires-Dist: accelerate; extra == "all"
Requires-Dist: bitsandbytes; extra == "all"
Dynamic: license-file

# Langtune: LoRA Fine-Tuning for Text LLMs

<div align="center">

<img alt="Langtune Logo" src="https://raw.githubusercontent.com/langtrain-ai/langtune/main/static/langtune-white.png" width="400" />

### Fine-tune your first LLM in under 5 minutes

[![PyPI version](https://img.shields.io/pypi/v/langtune.svg)](https://pypi.org/project/langtune/)
[![Downloads](https://pepy.tech/badge/langtune)](https://pepy.tech/project/langtune)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![Python](https://img.shields.io/badge/python-3.8%2B-blue)]()

</div>

---

## What You'll Need

```bash
# Quick system check
python --version 

# Check GPU support (Optional but recommended)
python -c "import torch; print('GPU ready!' if torch.cuda.is_available() else 'CPU mode - still works!')"
```

## Install LangTrain

```bash
# Step 1: Create a clean environment (recommended)
python -m venv langtrain-env
source langtrain-env/bin/activate  # Windows: langtrain-env\Scripts\activate

# Step 2: Install LangTune
pip install langtune

# Step 3: Verify it worked
python -c "import langtune; print('✅ LangTune installed!')"
```

## Train Your First Model

```python
from langtune import LoRATrainer

# Step 1: Define your training data
training_data = [
    {"user": "Hello!", "assistant": "Hi there! How can I help you today?"},
    {"user": "What can you do?", "assistant": "I can answer questions, have conversations, and help with various tasks!"},
    {"user": "Thanks!", "assistant": "You're welcome! Feel free to ask anything else."}
]

# Step 2: Create the trainer
# This sets up everything for you automatically
trainer = LoRATrainer(
    model_name="microsoft/DialoGPT-medium",
    output_dir="./my_first_chatbot",
)

# Step 3: Train!
trainer.train(training_data)

# Step 4: Test your model
response = trainer.chat("Hello!")
print(f"Your AI says: {response}")
```

## Use Your Trained Model

```python
from langtune import ChatModel

# Load your trained model
model = ChatModel.load("./my_first_chatbot")

# Have a conversation
print(model.chat("Hello!"))
print(model.chat("What can you do?"))
```

## Using Your Own Data

```python
from langtune import LoRATrainer

trainer = LoRATrainer(
    model_name="microsoft/DialoGPT-medium",
    output_dir="./custom_chatbot",
)

# Method 1: Load from a JSONL file
# File should contain: {"user": "...", "assistant": "..."}
trainer.train_from_file("my_conversations.jsonl")

# Method 2: Load from Hugging Face datasets
trainer.train_from_hub("your_username/your_dataset")
```

## Next Steps

1.  **Train a larger model**: Use `QLoRATrainer` for 4-bit quantization (runs Llama-3-8B on 6GB VRAM!).
2.  **Deploy as API**: Use `langtune.deploy("./my_model", port=8000)`.
3.  **Read the Docs**: Check out [langtrain.xyz/docs](https://langtrain.xyz/docs).

---

## Architecture Overview

Langtune uses a modular transformer backbone with LoRA adapters injected into attention and MLP layers.

```mermaid
flowchart TD
 subgraph LoRA_Adapters["LoRA Adapters"]
        LA1(["LoRA Adapter 1"])
        LA2(["LoRA Adapter 2"])
  end
    A(["Input Tokens"]) --> B(["Embedding Layer"])
    B --> D1(["Encoder Layer 1"])
    D1 --> D2(["Encoder Layer 2"])
    LA1 -.-> D1
    LA2 -.-> D2
    D2 --> F(["Output Logits"])
     LA1:::loraStyle
     LA2:::loraStyle
    classDef loraStyle fill:#e1f5fe,stroke:#0277bd,stroke-width:2px
```

## Contributing

Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md).

## License

MIT License. See [LICENSE](LICENSE).

## Citation

```bibtex
@software{langtune2025,
  author = {Pritesh Raj},
  title = {langtune: LLMs with Efficient LoRA Fine-Tuning},
  url = {https://github.com/langtrain-ai/langtune},
  year = {2025}
}
```

