UnslothConversationTrainer
Python template · sinapsis_unsloth.templates.training.unsloth_conversation_trainer
Overview
Template for conversation-based-fine-tuning on language models using Unsloth framework.
Handles the complete training pipeline including dataset preparation, template application, and model training with SFTTrainer.
Capabilities
Capabilities: not setInstallation
Install the published package using pip or uv.
pip install sinapsis-unsloth==1.0.0uv pip install sinapsis-unsloth==1.0.0uv add sinapsis-unsloth==1.0.0Configuration
Effective fields from the inspector schema, including nested Pydantic model fields.
Optional
Default: null
Optional
Default: null
The rank of the LoRA matrices. Higher rank allows for more expressivity but increases trainable parameters and memory usage. Defaults to 16.
Optional
Default: 16
Specifies how biases are handled. Options are "none", "all", or "lora_only". Unsloth optimizes for "none". Defaults to "none".
Optional
Default: "none"
The scaling factor for LoRA. A higher alpha places more emphasis on the adapter weights. Defaults to 16.
Optional
Default: 16
If True, uses Rank-Stabilized LoRA (scaling = alpha / sqrt(r)) instead of standard LoRA (scaling = alpha / r). Defaults to False.
Optional
Default: false
Configuration for LoftQ initialization. Used only if LoftQ is required. Defaults to an empty dict.
Optional
Default: null
The dropout probability for LoRA layers. Unsloth recommends 0.0 for optimized performance. Defaults to 0.0.
Optional
Default: 0
Random seed for initialization reproducibility. Defaults to 3407.
Optional
Default: 3407
List of module names to apply LoRA adapters to. Defaults to all linear layers ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"].
Optional
Default: ["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"]
List of additional modules (like "embed_tokens" or "lm_head") to be set as trainable and saved. Defaults to None.
Optional
Default: null
Enables gradient checkpointing to save VRAM. "unsloth" uses optimized kernels, True uses standard PyTorch checkpointing. Defaults to "unsloth".
Optional
Default: "unsloth"
Required
Default: null
Required
Default: null
Data type for model weights. Defaults to "auto".
Optional
Default: "auto"
Directory where models are cached. Defaults to SINAPSIS_CACHE_DIR.
Optional
Default: "/home/ariel/.cache/sinapsis"
Device mapping strategy for model parallelism. Defaults to "sequential".
Optional
Default: "sequential"
The name of the model to be used.
Required
Default: null
Whether to use 4-bit quantization. Defaults to True.
Optional
Default: true
Whether to use 8-bit quantization. Defaults to False.
Optional
Default: false
Random state for reproducibility. Defaults to 3407.
Optional
Default: 3407
Whether to use 16-bit quantization. Defaults to False.
Optional
Default: false
Maximum rank for LoRA layers. Defaults to 64.
Optional
Default: 64
Whether to enable fast inference mode. Defaults to False.
Optional
Default: false
Maximum sequence length for input data. Defaults to 2048.
Optional
Default: 2048
Whether to perform full fine-tuning. Defaults to False.
Optional
Default: false
Maximum GPU memory utilization as a fraction of total available memory. Defaults to 0.5.
Optional
Default: 0.5
Gradient checkpointing strategy. Defaults to "unsloth".
Optional
Default: "unsloth"
Optional
Default: null
Whether to group multiple sequences into fixed-length blocks to improve computational efficiency. Defaults to False.
Optional
Default: false
Type of loss to use. "nll" (Negative Log-Likelihood) or "dft" (Dynamic Fine-Tuning). Defaults to "nll".
Optional
Default: "nll"
Maximum length of the tokenized sequence. Sequences longer than this are truncated. Defaults to 1024.
Optional
Default: 1024
Whether to pack the eval dataset. Defaults to False.
Optional
Default: false
Number of processes to use for processing the dataset. Defaults to None.
Optional
Default: null
Strategy for packing sequences. "bfd" (Best-Fit Decreasing) or "wrapped". Defaults to "bfd".
Optional
Default: "bfd"
Name of the column containing the text data. Defaults to "text".
Optional
Default: "text"
Whether to compute loss only on the assistant part of the sequence. Supported for conversational datasets. Defaults to False.
Optional
Default: false
Whether to compute loss only on the completion part of the sequence. Supported for prompt-completion datasets. Defaults to None.
Optional
Default: null
Whether to offload activations to the CPU to save VRAM. Defaults to False.
Optional
Default: false
Required
Default: null
Role mapping configuration.
Optional
Default: null
Key name for the role field.
Optional
Default: "role"
Value identifying the user role.
Optional
Default: "user"
Key name for the content field.
Optional
Default: "content"
Value identifying the assistant role.
Optional
Default: "assistant"
Whether to map the EOS token.
Optional
Default: true
The name of the target chat template (e.g., 'deepseek-r1').
Required
Default: null
System message to prepend to conversations.
Optional
Default: null
Required
Default: null
Optional
Default: null
Optional
Default: null
Random seed for shuffling.
Optional
Default: null
Whether to keep the shuffled dataset in memory.
Optional
Default: false
Optional
Default: true
Whether to shuffle the dataset. Defaults to False. shuffle_args (ShuffleArgs): Arguments passed to the shuffle method.
Optional
Default: false
Optional
Default: null
Meaningful description for the progress bar. remove_columns (str | list[str] | None): Columns to remove after mapping.
Optional
Default: null
Whether to provide a batch of examples to the function.
Optional
Default: false
Number of processes for multiprocessing.
Optional
Default: 0
Number of examples per batch. Defaults to 1000.
Optional
Default: 1000
Optional
Default: false
Optional
Default: true
Required
Default: null
The configuration name of the dataset.
Optional
Default: null
The path or identifier of the dataset (e.g., 'imdb', 'json').
Required
Default: null
Which split of the data to load (e.g., 'train').
Optional
Default: null
Path to the directory containing the data files.
Optional
Default: null
Optional
Default: null
Number of processes for loading.
Optional
Default: null
Directory to read/write data. Defaults to SINAPSIS_CACHE_DIR.
Optional
Default: "/home/ariel/.cache/sinapsis"
Path(s) to source data files.
Optional
Default: null
Input dataset format.
Required
Default: null
Optional
Default: null
Optional
Default: null
Window overlap for overflowing tokens. return_tensors (str | None): If set, will return tensors instead of lists ('pt', 'tf', 'np').
Optional
Default: 0
Padding strategy ("longest", "max_length", etc.).
Optional
Default: "do_not_pad"
Optional
Default: true
Maximum length of the returned list and/or tensor.
Optional
Default: null
Truncation strategy.
Optional
Default: "do_not_truncate"
Optional
Default: null
Whether to encode the sequences with special tokens.
Optional
Default: true
Optional
Default: false
Whether to pre-tokenize the dataset before training. tokenization_args (TokenizerArgs): Arguments passed to the tokenizer.
Optional
Default: false
Arguments passed to the map function during tokenization.
Optional
Default: null
Meaningful description for the progress bar. remove_columns (str | list[str] | None): Columns to remove after mapping.
Optional
Default: null
Whether to provide a batch of examples to the function.
Optional
Default: false
Number of processes for multiprocessing.
Optional
Default: 0
Number of examples per batch. Defaults to 1000.
Optional
Default: 1000
Optional
Default: false
Optional
Default: true
Arguments for converting Alpaca to ShareGPT.
Optional
Default: null
Random seed for reproducibility.
Optional
Default: 3407
Prompt string for merging instruction and input.
Optional
Default: ""
Column name for the merged instruction.
Optional
Default: "instruction"
Column name for the response output.
Optional
Default: "output"
Whether to remove columns not used in conversion.
Optional
Default: true
Number of additional messages for multi-turn simulation.
Optional
Default: 1
Optional
Default: null
Whether to use BF16 16-bit precision (requires Ampere+ GPU).
Optional
Default: false
Whether to use FP16 16-bit precision.
Optional
Default: false
Optional
Default: 3407
Optimizer name (e.g., "adamw_torch", "adamw_8bit").
Optional
Default: "adamw_torch"
Optional
Default: false
Optional
Default: null
Total number of training steps. Overrides epochs.
Optional
Default: null
List of integrations to report to (e.g., "wandb").
Optional
Default: "none"
Number of steps between evaluations.
Optional
Default: null
Directory where checkpoints and model outputs will be saved.
Optional
Default: "trainer_output"
Number of steps between saves.
Optional
Default: 500
Whether to push the model to the Hub after training.
Optional
Default: false
Optional
Default: null
Ratio of total steps used for linear warmup.
Optional
Default: 0
Optional
Default: null
Weight decay to apply to all layers except bias/LayerNorm.
Optional
Default: 0
Strategy for evaluation.
Optional
Default: "no"
Initial learning rate for AdamW.
Optional
Default: 0.00005
Number of steps between logging events.
Optional
Default: 500
Optional
Default: 1
Strategy for saving checkpoints.
Optional
Default: "steps"
Optional
Default: false
Optional
Default: "steps"
Total number of training epochs.
Optional
Default: 3
Scheduler type (e.g., "linear", "cosine").
Optional
Default: "linear"
Optional
Default: false
Optional
Default: false
If True, overwrite the content of the output directory.
Optional
Default: false
Optional
Default: "loss"
Optional
Default: true
Optional
Default: 0
Optional
Default: false
Number of steps to accumulate evaluation predictions.
Optional
Default: null
Optional
Default: null
Batch size per GPU for evaluation.
Optional
Default: 8
Number of update steps to accumulate gradients for.
Optional
Default: 1
Batch size per GPU for training.
Optional
Default: 8
Optional
Default: null
Padding strategy.
Optional
Default: "do_not_pad"
Max sequence length for padding.
Optional
Default: null
Token ID used for padding labels. Defaults to -100.
Optional
Default: -100
Whether to only compute loss on assistant responses data_collator_kwargs (dict[str, Any]): Custom arguments for conversation data collation
Optional
Default: true
Optional
Default: false
Configuration example
Example from the Python docstring:
agent:
name: my_test_agent
templates:
- template_name: InputTemplate
class_name: InputTemplate
attributes: {}
- template_name: UnslothConversationTrainer
class_name: UnslothConversationTrainer
template_input: InputTemplate
attributes:
model_args:
model_name: 'unsloth/DeepSeek-R1-Distill-Qwen-7B'
max_seq_length: 2048
dtype: auto
load_in_4bit: true
use_gradient_checkpointing: unsloth
gpu_memory_utilization: 0.5
random_state: 3407
max_lora_rank: 64
lora_args:
r: 16
target_modules:
- q_proj
- k_proj
- v_proj
- o_proj
- gate_proj
- up_proj
- down_proj
lora_alpha: 16
lora_dropout: 0.0
bias: none
use_gradient_checkpointing: unsloth
random_state: 3407
use_rslora: false
modules_to_save: null
trainer_args:
dataset_text_field: text
dataset_num_proc: null
max_length: 1024
packing: false
training_args:
per_device_train_batch_size: 4
gradient_accumulation_steps: 8
warmup_ratio: 0.1
num_train_epochs: 2
learning_rate: 0.00005
embedding_learning_rate: 0.00001
fp16: false
bf16: true
logging_steps: 1
optim: adamw_8bit
weight_decay: 0.01
lr_scheduler_type: linear
seed: 3407
output_dir: outputs
save_strategy: "epoch"
report_to: none
train_dataset:
loader_args:
path: 'json'
data_files: 'path/to/dataset.jsonl'
split: train
map_args:
batched: false
batch_size: 1000
num_proc: 0
keep_in_memory: false
load_from_cache_file: true
shuffle:
enabled: true
args:
seed: 3407
pre_tokenize:
enabled: false
input_format: 'alpaca'
to_sharegpt_args:
merged_prompt: '{instruction}[[{input}]]'
merged_column_name: instruction
output_column_name: output
remove_unused_columns: true
conversation_extension: 1
random_state: 3407
resume_from_checkpoint: false
save_path: 'path/to/fine-tuned-lora/'
chat_template:
mapping:
role: role
content: content
user: user
assistant: assistant
map_eos_token: true
system_message: "You're a useful assistant"
target_format: 'deepseek-r1'
train_responses_only: trueShow schema-based configuration skeleton
templates:
- template_name: "UnslothConversationTrainer"
class_name: "UnslothConversationTrainer"
attributes:
lora_args:
r: 16
bias: "none"
lora_alpha: 16
use_rslora: false
loftq_config: {}
lora_dropout: 0
random_state: 3407
target_modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
modules_to_save: null
use_gradient_checkpointing: "unsloth"
save_path: "<required>"
model_args:
dtype: "auto"
cache_dir: "/home/ariel/.cache/sinapsis"
device_map: "sequential"
model_name: "<required>"
load_in_4bit: true
load_in_8bit: false
random_state: 3407
load_in_16bit: false
max_lora_rank: 64
fast_inference: false
max_seq_length: 2048
full_finetuning: false
gpu_memory_utilization: 0.5
use_gradient_checkpointing: "unsloth"
trainer_args:
packing: false
loss_type: "nll"
max_length: 1024
eval_packing: false
dataset_num_proc: null
packing_strategy: "bfd"
dataset_text_field: "text"
assistant_only_loss: false
completion_only_loss: null
activation_offloading: false
chat_template:
mapping:
role: "role"
user: "user"
content: "content"
assistant: "assistant"
map_eos_token: true
target_format: "<required>"
system_message: null
train_dataset:
shuffle:
args:
seed: null
keep_in_memory: false
load_from_cache_file: true
enabled: false
map_args:
desc: null
batched: false
num_proc: 0
batch_size: 1000
keep_in_memory: false
load_from_cache_file: true
loader_args:
name: null
path: "<required>"
split: null
data_dir: null
features: null
num_proc: null
cache_dir: "/home/ariel/.cache/sinapsis"
data_files: null
input_format: "<required>"
pre_tokenize:
args:
stride: 0
padding: "do_not_pad"
verbose: true
max_length: null
truncation: "do_not_truncate"
padding_side: null
add_special_tokens: true
is_split_into_words: false
enabled: false
map_args:
desc: null
batched: false
num_proc: 0
batch_size: 1000
keep_in_memory: false
load_from_cache_file: true
to_sharegpt_args:
random_state: 3407
merged_prompt: ""
merged_column_name: "instruction"
output_column_name: "output"
remove_unused_columns: true
conversation_extension: 1
training_args:
bf16: false
fp16: false
seed: 3407
optim: "adamw_torch"
use_cpu: false
data_seed: null
max_steps: null
report_to: "none"
eval_steps: null
output_dir: "trainer_output"
save_steps: 500
push_to_hub: false
hub_model_id: null
warmup_ratio: 0
warmup_steps: null
weight_decay: 0
eval_strategy: "no"
learning_rate: 0.00005
logging_steps: 500
max_grad_norm: 1
save_strategy: "steps"
save_only_model: false
logging_strategy: "steps"
num_train_epochs: 3
lr_scheduler_type: "linear"
logging_first_step: false
dataloader_drop_last: false
overwrite_output_dir: false
metric_for_best_model: "loss"
remove_unused_columns: true
dataloader_num_workers: 0
load_best_model_at_end: false
eval_accumulation_steps: null
torch_empty_cache_steps: null
per_device_eval_batch_size: 8
gradient_accumulation_steps: 1
per_device_train_batch_size: 8
data_collator_args:
padding: "do_not_pad"
max_length: null
label_pad_token_id: -100
train_responses_only: true
resume_from_checkpoint: false
Inheritance
sinapsis_unsloth.templates.training.unsloth_fine_tuning_base.UnslothFineTuningBaseEnvironment variables
Environment definitions belong to their canonical Python modules.
No directly related environment variables listed.