Skip to content

lora

diapason.learning.training.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.

LoRATrainer

Fine-tune a local causal LM with LoRA (or QLoRA) adapters.

Parameters

config: LoRA training configuration. model_name: HuggingFace model identifier or local path. device: PyTorch device string. None auto-detects (cuda > mps > cpu).

Raises

ImportError If torch is not installed.

prepare_dataset(pairs)

Convert SFT pairs to tokenized examples.

Each returned dict contains input_ids, attention_mask, and text (the raw formatted string before tokenization).

Parameters

pairs: List of dicts with at least input and output keys, as produced by :class:TrainingDataMiner.extract_sft_pairs.

train(pairs)

Run LoRA fine-tuning on the given SFT pairs.

Parameters

pairs: List of dicts with at least input and output keys.

Returns

dict Training summary with keys: status, epochs, total_steps, avg_loss, adapter_path, training_samples.

LoRATrainingConfig dataclass

Configuration for LoRA / QLoRA fine-tuning.