Quick start
Install the SDK, write a small dataset, fine-tune an open model on your own GPU and save weights you can run anywhere.
- Python 3.8+
- NVIDIA GPU
1. Install
Install the SDK with its training extras and Langtune, inside a virtual environment, on a machine with an NVIDIA GPU.
bash1pip install "langtrain-ai[train]" langtune2. Prepare your data
Create a
.jsonlfile. Each line is one conversation: a messages array in the same format as the OpenAI chat API.json1{"messages": [{"role": "user", "content": "What is Langtrain?"}, {"role": "assistant", "content": "A platform for fine-tuning open models."}]}2{"messages": [{"role": "user", "content": "How do I start?"}, {"role": "assistant", "content": "Write a JSONL file like this one, then train."}]}3. Train
Load the model in 4-bit, add a QLoRA adapter and train. Only the adapter learns; the base model stays frozen, so an 8B model fits on a single 24 GB GPU.
python1from datasets import load_dataset2from langtrain import FastLanguageModel34model, tokenizer = FastLanguageModel.from_pretrained(5 "meta-llama/Llama-3.1-8B-Instruct",6 load_in_4bit=True,7)8model = FastLanguageModel.get_peft_model(model, r=16, method="qlora")910dataset = load_dataset("json", data_files="training_data.jsonl", split="train")11FastLanguageModel.train(model, tokenizer, dataset, output_dir="./output")4. Try it and keep the weights
Ask it something, then merge the adapter into the base model. The result is a standard Hugging Face model folder that llama.cpp, vLLM and Ollama can run.
python1FastLanguageModel.for_inference(model, tokenizer)2print(FastLanguageModel.generate(model, tokenizer, "How do I start?"))34FastLanguageModel.save_pretrained(model, tokenizer, "./my-model", merge_before_save=True)