TrainingArguments
Arguments for GRADIEND training (HF Trainer–style, single training_args class).
Pass to Trainer at construction: Trainer(model=..., training_args=TrainingArguments(...)). Used directly by the core training loop.
activation_decoder
class-attribute
instance-attribute
Decoder activation name (e.g. 'id', 'tanh'). None = model default ('id').
activation_encoder
class-attribute
instance-attribute
Encoder activation name (e.g. 'tanh', 'gelu', 'relu'). None = model default ('tanh').
add_identity_for_other_classes
class-attribute
instance-attribute
If True, add identity (factual==alternative) examples for classes not in the target classes used for training.
analyze_seed_stability
class-attribute
instance-attribute
If True, require at least min_convergent_seeds convergent seeds after multi-seed training and forbid saved_seed_runs='best_only'. Multi-seed evaluation uses trainer.multi_seed().
base_gradient_batch_size
class-attribute
instance-attribute
Number of raw training examples merged into one base-model loss/backward call, producing one base-gradient vector.
base_model_device_map
class-attribute
instance-attribute
Hugging Face device_map for the base model. None auto-detects large models on >3 GPUs, False disables device_map, and strings/dicts are passed through explicitly.
base_model_max_memory
class-attribute
instance-attribute
Optional Hugging Face max_memory map for base-model device placement. When unset and base_model_device_map='auto' on multiple GPUs, GPU0 is reserved for GRADIEND automatically.
bias_decoder
class-attribute
instance-attribute
Whether the decoder linear layer uses a bias term. None = model default (True).
chat_template_date
class-attribute
instance-attribute
Fixed date (ISO YYYY-MM-DD) for chat templates that write the current date into the prompt (Llama 3.1 and
later, gpt-oss). The template never reads the system clock, because the training rows would change with the day
they are built. None (default) uses gradiend.trainer.text.common.chat_format.DEFAULT_CHAT_TEMPLATE_DATE,
the date Llama's own templates fall back to. A template that does not ask for the date ignores it. When a
template does ask for it, the trainer stores the date actually used here (also when it was the default), the
record of a trained model keeps it, and a loaded model uses it, so changing the default later never changes an
existing model.
clm_unalignable_rows
class-attribute
instance-attribute
Policy for unalignable decoder-only CLM rows where one target is a token-prefix of the other or token sequences are identical.
"error"(default): fail fast with an aggregated error during pre-training check."drop": drop unalignable rows during pre-training check and log counts per feature class.
convergent_mean_by_class_threshold
class-attribute
instance-attribute
Optional additional convergence criterion: minimum absolute mean encoded value per target class.
Default: 0.5 when convergent_metric='correlation'. Set to None to disable the mean-based check and use only convergent_score_threshold. When set, convergence requires BOTH |correlation| >= convergent_score_threshold AND min(|mean|) over non-zero target classes >= convergent_mean_by_class_threshold at the best checkpoint step. For correlation-based convergence, the two non-zero target classes must also have opposite-sign mean encodings at the best checkpoint step (their product must be negative).
convergent_metric
class-attribute
instance-attribute
Metric for convergence: "correlation" or "loss". Defaults to correlation unless supervised_decoder.
convergent_score_threshold
class-attribute
instance-attribute
Threshold for convergence. Defaults to 0.6 for correlation; required for loss.
criterion
class-attribute
instance-attribute
Loss function; None = MSELoss().
dataset_trust_remote_code
class-attribute
instance-attribute
Optional trust_remote_code value for HuggingFace datasets.load_dataset. None means do not pass the keyword.
decoder_eval_feature_factors
class-attribute
instance-attribute
Feature factors for decoder grid search. None = derive from trainer target classes.
decoder_eval_lrs
class-attribute
instance-attribute
Learning rates for decoder grid search. None = DecoderEvaluator defaults (1/2/5 grid from 100 to 1e-3).
decoder_eval_max_size_neutral
class-attribute
instance-attribute
Max samples for decoder neutral evaluation data (also LMS text cap). None = use default behavior.
decoder_eval_max_size_training_like
class-attribute
instance-attribute
Max samples for decoder training-like evaluation data. None = use default behavior.
decoder_mlm_head_batch_size
class-attribute
instance-attribute
Batch size used when prediction_objective="clm_mlm_head" trains the auxiliary head.
decoder_mlm_head_epochs
class-attribute
instance-attribute
Epochs used when prediction_objective="clm_mlm_head" has to train the auxiliary head.
decoder_mlm_head_lr
class-attribute
instance-attribute
Learning rate used when prediction_objective="clm_mlm_head" trains the auxiliary head.
decoder_mlm_head_max_size
class-attribute
instance-attribute
Optional per-label cap for auxiliary decoder MLM-head training data.
decoder_sequence_cloze_rhs_window
class-attribute
instance-attribute
Right-context token window for clm_sequence_cloze / seq2seq_decoder_sequence_cloze scoring and training. -1 uses the full RHS.
delete_models
class-attribute
instance-attribute
If True, delete intermediate model files at end (e.g. .bin). This can be used to save disk space if you only care about metrics and not the model itself. Does not delete the whole model directory, which may contain other files (e.g. config, pre/post-prune results).
do_eval
class-attribute
instance-attribute
Whether to run evaluation during training.
encoder_decoder_same_device
class-attribute
instance-attribute
If True, place encoder and decoder on the same GPU (cuda:0), giving the base model the rest. Useful for large base models with pre-pruning: encoder+decoder are small and can share GPU 0; base model can use cuda:1 (2 GPUs) or cuda:2 (3+ GPUs). If False (default), encoder and decoder are split across cuda:0 and cuda:1 when 2+ GPUs are available.
encoder_eval_balance
class-attribute
instance-attribute
If True, balance encoder evaluation data per feature_class_id. If False, use natural class distribution.
encoder_eval_max_size
class-attribute
instance-attribute
Max samples for encoder evaluation outside training (e.g. analysis, manual evaluate_encoder). None = use all available.
encoder_eval_train_max_size
class-attribute
instance-attribute
Max samples for encoder evaluation during training (fast estimate; per-feature_class when available). None = use encoder_eval_max_size.
eval_steps
class-attribute
instance-attribute
Run evaluation every eval_steps (when eval_strategy == 'steps').
eval_strategy
class-attribute
instance-attribute
When to run evaluation: 'steps' (every eval_steps) or 'no'.
evaluate_fn
class-attribute
instance-attribute
Custom evaluation function; None = default (encoder correlation on eval data).
experiment_dir
class-attribute
instance-attribute
Root directory for this experiment. When set, default paths use subpaths under it (model, encoded_values, etc.). One experiment dir holds one model. Trainer.run_id (when set) is used as subdir under this.
fail_on_non_convergence
class-attribute
instance-attribute
If True, raise when training finishes and convergent_count < min_convergent_seeds (requires min_convergent_seeds > 0).
gradiend_batch_size
class-attribute
instance-attribute
Number of base-gradient vectors stacked into one GRADIEND optimizer step. Defaults to 1.
gradient_timing_steps
class-attribute
instance-attribute
If > 0, log timing for gradient-row creation every N rows.
highlight_non_convergence
class-attribute
instance-attribute
If True, append a non-convergence marker (†) to plot/tick labels for non-converged runs.
include_other_classes
class-attribute
instance-attribute
If True, encoder evaluation includes all class transitions in the split, not just the trained target pair. Applies when all_classes has more than two entries. Affects encoder metrics, encoder plots, and suite cross-encoding plots built from encoder evaluation. Set on TrainingArguments or pass include_other_classes=True to evaluate_encoder().
instruction_model
class-attribute
instance-attribute
Whether the model is an instruction-tuned ("Instruct") model, whose rows are chat prompts.
None (default): decided by the model name. The base name (the last path component, for a hub id the part
after the organisation) split at non-alphanumeric characters must contain one of the words instruct,
chat or it (case-insensitive), e.g. Qwen2.5-1.5B-Instruct, gemma-2-2b-it,
Llama-2-7b-chat-hf. True: chat-format the model whatever its name. False: read plain text even if the
name matches. The decision in force (always True or False, also for a plain model) is stored with the
trained model, and a loaded model keeps it, whatever the name rule says later. A model saved before the
decision was stored was trained under the old rule, so it is decided by that rule: "instruct" anywhere in
the name (any case).
label_token_protocol
class-attribute
instance-attribute
Which token a decoder-only (clm_next_token) training row supervises.
"first_differing_token" (default): the label is the first token where the factual and the
alternative target differ; tokens they share are appended to the context
(:func:~gradiend.trainer.text.prediction.clm_alignment.align_clm_divergence). When the two targets
already differ in their first token and the target follows whitespace, this is the leading-space
variant of the label (▁she / Ġshe, tokenizer(" " + label)), the rule
:meth:TextPredictionModelWithGradiend.create_inputs uses. Rows without an alternative use that
leading-space rule. Rows that cannot be aligned (identical targets, or one a token-prefix of the
other) follow :attr:clm_unalignable_rows.
"no_leading_space": the rule of gradiend 0.2.5 and earlier, vocab[label] (the no-space variant
she, else the first id of tokenizer(label)). No alignment, no pre-training check. It exists
only to reproduce models trained with those releases.
Settings saved with the old names canonical / legacy still load (:meth:from_dict), and a
saved dict without this key loads as "no_leading_space", so trained artifacts are never
silently re-interpreted.
latent_dim
class-attribute
instance-attribute
GRADIEND latent dimension (number of features). None = model default (1).
learning_rate
class-attribute
instance-attribute
Peak learning rate. "tune" searches it automatically before training (see lr_search_config).
lr_search_config
class-attribute
instance-attribute
Options of the learning-rate search used for learning_rate="tune" and trainer.tune_learning_rate() (defaults if None).
mask_placeholder
class-attribute
instance-attribute
Dataset-level prediction placeholder used inside masked text templates.
This is independent of tokenizer.mask_token. Prefer setting
TextPredictionConfig.mask_placeholder with the data schema (e.g.
mask_placeholder="[PRONOUN]"). A non-default value here still overrides
when the config field is left at its default.
max_steps
class-attribute
instance-attribute
If > 0, total number of steps; overrides num_train_epochs. -1 = use epochs.
min_convergent_seeds
class-attribute
instance-attribute
Stop once this many seeds have converged. None = run max_seeds. 0 is invalid.
model_use_cache
class-attribute
instance-attribute
When False (default), pass use_cache=False to decoder model forward during training (KV cache disabled). Use True only for inference/generation. Decoder-only MLM head training respects this via train_decoder_only_mlm_head.
normalize_gradiend
class-attribute
instance-attribute
Whether to normalize GRADIEND encodings during training, i.e., first target class is encoded to +1 and second to -1. This is recommended for enhanced comparability between runs.
output_dir
class-attribute
instance-attribute
Directory to save the trained model. If None and experiment_dir is set, uses experiment_dir/model (or experiment_dir/run_id/model when Trainer.run_id is set). Otherwise must be set explicitly.
params
class-attribute
instance-attribute
If set, only these parameter names or wildcards are included in the GRADIEND param map when building from a base model. None = include all backbone parameters (default). Enables future params selection processes.
positive_class
class-attribute
instance-attribute
Optional canonical positive feature class used for binary cross-encoding comparisons. When None, comparison utilities may infer it conservatively from target classes via the non_/non- prefix heuristic. Ignored for normal training.
post_prune_config
class-attribute
instance-attribute
If set, post-prune is run automatically after training. The pruned model is kept in memory for subsequent evaluation. No disk save unless you save explicitly.
pre_prune_config
class-attribute
instance-attribute
If set, pre-prune is run automatically before training. The pruned model is kept in memory; training then uses it. No disk save unless you save explicitly.
precompute_gradient_batches
class-attribute
instance-attribute
Whether to precompute the next gradient row asynchronously. None (default): auto-enable only when the base model is sharded and multiple CUDA devices are available. False: never precompute. True: always precompute (thread-safe via ModelWithGradiend.exclusive_base_gradient_access during base forward/backward).
precompute_gradient_buffer_size
class-attribute
instance-attribute
Number of already-computed gradient rows to keep in the asynchronous precompute queue.
prediction_objective
class-attribute
instance-attribute
Prediction objective for text-gradient training and decoder probability scoring.
Supported: auto, mlm_mask_token, clm_next_token, clm_mlm_head,
clm_sequence_cloze, seq2seq_decoder (experimental), seq2seq_decoder_sequence_cloze (experimental),
seq2seq_encoder_mlm.
auto: seq2seq models → seq2seq_encoder_mlm; decoder-only → clm_next_token (or cached
clm_mlm_head when a saved head exists); else mlm_mask_token.
reuse_pre_prune
class-attribute
instance-attribute
If True, cache pre-prune keep_idx under experiment_dir/cache/pre_prune for reuse across seeds in one train() call. Cache is removed when training finishes.
runtime_monitor
class-attribute
instance-attribute
If True, write persistent JSONL runtime diagnostics under the training output directory.
runtime_monitor_interval
class-attribute
instance-attribute
Seconds between runtime monitor heartbeat samples.
runtime_monitor_system_stats
class-attribute
instance-attribute
If True, runtime monitor heartbeats include CPU/GPU memory stats.
save_only_best
class-attribute
instance-attribute
If True, keep only the best checkpoint (by evaluation correlation).
save_steps
class-attribute
instance-attribute
Save checkpoint every save_steps when save_strategy == 'steps'.
save_strategy
class-attribute
instance-attribute
'best' (default): keep only best checkpoint by correlation. 'steps': also save periodic checkpoints every save_steps. 'no': no checkpointing.
saved_seed_runs
class-attribute
instance-attribute
Multi-seed retention policy: 'best_only', 'all_convergent', or 'all_tried'.
seed
class-attribute
instance-attribute
Random seed for reproducible runs (default 0). The Trainer sets PyTorch/numpy/Python RNG, CUDA determinism, and CUBLAS/OMP env vars; data pipelines use this as random_state. Also the base for multi-seed runs (seed+i). Pass seed=None for non-deterministic runs. If results still vary, call set_seed(42) at the very start of your script or set env CUBLAS_WORKSPACE_CONFIG=:4096:8 and OMP_NUM_THREADS=1 before starting Python.
seed_runs_dir
class-attribute
instance-attribute
Directory for per-seed runs. Defaults to experiment_dir/seeds when experiment_dir is set.
seed_selection_eval_max_size
class-attribute
instance-attribute
Max samples for encoder evaluation when selecting the best seed. None = use encoder_eval_max_size.
seed_stability_part
class-attribute
instance-attribute
Importance part used for convergent-seed top-k stability summaries.
seed_stability_topk
class-attribute
instance-attribute
Top-k selection used for stability summaries across convergent seeds. None disables the report.
source
class-attribute
instance-attribute
Source for GRADIEND input: 'factual', 'alternative', or 'diff'.
split_resplit_per_seed
class-attribute
instance-attribute
When split_col is "heldout" or None, re-draw splits per training seed.
For "heldout", vocabulary groups rotate (see split_resplit_strategy).
For None, rows are reshuffled randomly. False keeps the same assignment across
multi-seed runs (using TrainingArguments.seed).
split_resplit_strategy
class-attribute
instance-attribute
Strategy used when split_resplit_per_seed=True.
"random" redraws splits from each seed. "balanced_cycle" rotates
canonical target groups through train/validation/test across seed indices
so ratios such as 60/20/20 over five seed slots place each word in train
three times, validation once, and test once.
supervised_decoder
class-attribute
instance-attribute
If True, train only the GRADIEND decoder: decoder(labels) vs target gradients (MSE). Baseline mode. Cannot be True together with supervised_encoder.
supervised_encoder
class-attribute
instance-attribute
If True, train only the GRADIEND encoder: encode(source) vs labels (MSE). Baseline mode.
target
class-attribute
instance-attribute
Target for GRADIEND output: 'factual', 'alternative', or 'diff'.
torch_dtype
class-attribute
instance-attribute
dtype for model; None = torch.float32.
train_batch_size
class-attribute
instance-attribute
Alias/default for base_gradient_batch_size. Does not affect gradiend_batch_size.
train_max_size
class-attribute
instance-attribute
If set, cap training samples per feature_class_id (downsampling).
Note: Balancing is handled automatically by the dataset scheduler via oversampling (cycling through balance groups). This parameter primarily reduces total dataset size for memory/performance. None = use all data.
trust_remote_code
class-attribute
instance-attribute
If True, pass trust_remote_code=True when loading models/tokenizers from Hugging Face (e.g. for EuroBERT).
use_cache
class-attribute
instance-attribute
Training checkpoint reuse policy.
False: always retrain even when a saved model exists.True: reuse when a saved model exists and matches the training cache fingerprint."always": reuse any saved model at the output path (skip fingerprint matching)."only_convergent": same fingerprint check asTrue, but only when the saved run meetsmin_convergent_seeds(per-seed convergence for individual seed dirs; aggregate count for the selected model).
use_cached_gradients
class-attribute
instance-attribute
Whether to use cached gradients if available. Using cached gradients speeds up training and evaluation, but leads to exhaustive memory usage (in memory) and/or on disk (in cached files).
__post_init__
Source code in gradiend/trainer/core/arguments.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
__str__
Source code in gradiend/trainer/core/arguments.py
_with_overrides
A copy of these arguments with overrides applied; keys that are not fields are ignored.
This is how user-supplied keyword arguments are merged into arguments (Trainer.train(**overrides),
gradiend.trainer.core.train(**kwargs)). Every field that is not overridden keeps this instance's value,
so a default is the current default; :meth:from_dict alone would read a missing key as an old record.
Source code in gradiend/trainer/core/arguments.py
from_dict
classmethod
Read a serialized record (e.g. loaded from JSON). Canonical keys only.
A key missing from the record was written before that key existed and takes the value of those releases:
a record without label_token_protocol loads as "no_leading_space". This reads records; it is not
how arguments are built from user input (use TrainingArguments(...), whose defaults are the current ones).
Source code in gradiend/trainer/core/arguments.py
get
to_dict
Dict for serialization (excludes callables and nn.Module). Canonical keys only.