lora
lora
¶
LoRATrainer — fine-tune local models via LoRA/QLoRA from trace-derived SFT pairs.
All torch, transformers, and peft imports are guarded so the
module can be imported without GPU dependencies. The :class:LoRATrainingConfig
dataclass works without any optional deps; :class:LoRATrainer raises
ImportError at construction time when torch is unavailable.
Classes¶
LoRATrainingConfig
dataclass
¶
LoRATrainingConfig(lora_rank: int = 16, lora_alpha: int = 32, lora_dropout: float = 0.05, target_modules: List[str] = (lambda: ['q_proj', 'v_proj'])(), num_epochs: int = 3, batch_size: int = 4, learning_rate: float = 2e-05, weight_decay: float = 0.01, warmup_ratio: float = 0.1, max_grad_norm: float = 1.0, max_seq_length: int = 2048, use_4bit: bool = False, output_dir: str = 'checkpoints/lora', save_every_n_epochs: int = 1, gradient_checkpointing: bool = True)
Configuration for LoRA / QLoRA fine-tuning.
LoRATrainer
¶
LoRATrainer(config: LoRATrainingConfig, *, model_name: str = 'Qwen/Qwen3-0.6B', device: Optional[str] = None)
Fine-tune a local causal LM with LoRA (or QLoRA) adapters.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
LoRA training configuration.
TYPE:
|
model_name
|
HuggingFace model identifier or local path.
TYPE:
|
device
|
PyTorch device string.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If |
Source code in src/openjarvis/learning/training/lora.py
Functions¶
prepare_dataset
¶
Convert SFT pairs to tokenized examples.
Each returned dict contains input_ids, attention_mask,
and text (the raw formatted string before tokenization).
| PARAMETER | DESCRIPTION |
|---|---|
pairs
|
List of dicts with at least
TYPE:
|
Source code in src/openjarvis/learning/training/lora.py
train
¶
Run LoRA fine-tuning on the given SFT pairs.
| PARAMETER | DESCRIPTION |
|---|---|
pairs
|
List of dicts with at least
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Training summary with keys: |