TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Antisource/heronaisec/llms.txt
Use this file to discover all available pages before exploring further.
train module encapsulates all Hugging Face Trainer configuration and fine-tuning execution. It is intentionally isolated from attack generation, evaluation, and experiment orchestration — its only job is to wire together a TrainingArguments object, a DataCollatorWithPadding, and a Trainer, then execute the training loop and persist the outputs. Both model weights and the tokenizer are saved atomically at the end of train_model() to ensure that every checkpoint directory is self-contained and immediately loadable.
Functions
build_trainer()
Construct a fully configured Hugging FaceTrainer instance.
Creates a TrainingArguments object with opinionated defaults for reproducible research (logging_strategy="epoch", save_strategy="epoch", report_to="none"), attaches a DataCollatorWithPadding for efficient dynamic padding, and returns a Trainer ready to call .train() on.
The model to fine-tune. Typically produced by
build_model() or load_model() from src.models.A PyTorch-formatted
Dataset containing "input_ids", "attention_mask", and "label" columns. Prepare with prepare_for_training() from src.data.The tokenizer matching the model checkpoint. Passed to the
Trainer as processing_class=tokenizer and to DataCollatorWithPadding for dynamic padding. Also saved alongside model weights by train_model().Directory where per-epoch checkpoints are written by the
Trainer. Pass a path inside your run directory (e.g. "results/run_01/checkpoints").Total number of training epochs (
num_train_epochs).Peak learning rate for the AdamW optimiser. Cast to
float internally to tolerate YAML-loaded values.Per-device training batch size (
per_device_train_batch_size).L2 regularisation coefficient applied to all non-bias parameters. Cast to
float internally.Random seed passed to
TrainingArguments for reproducible data sampling and weight initialisation within the Trainer.A configured
Trainer instance. Call .train() on the result, or pass directly to train_model().report_to="none" disables all experiment-tracker integrations (Weights & Biases, TensorBoard, etc.) by default. To enable logging, override this in your config and pass the value explicitly when calling build_trainer().train_model()
Execute the training loop and save the final model checkpoint and tokenizer. Callstrainer.train(), then saves the model via trainer.save_model(save_directory) and the tokenizer via tokenizer.save_pretrained(save_directory). This ensures the checkpoint directory is self-contained: it holds the model weights, the model config, and the tokenizer files needed to reload for inference or further fine-tuning.
A configured
Trainer instance, typically from build_trainer().Directory to write the final checkpoint. Both model and tokenizer are saved here. This is distinct from the per-epoch
output_dir in TrainingArguments, though they can be the same path.The tokenizer to save alongside the model weights. Should be the same tokenizer used to tokenize
train_dataset.The trained
trainer.model object, which remains on the same device it was trained on.