YAML configuration¶
Every run is described by a single YAML file loaded with CONFIG.from_yaml. The
schema is a set of pydantic models in
micm_nlp.config.
Two properties are worth knowing before reading the reference below.
Every section accepts extra keys. All config sections inherit from a permissive base, so a YAML file can carry keys the schema does not declare and runtime code can attach computed attributes. Validation catches the fields that matter without blocking the rest.
Class selection lives in YAML. model.pretrained.cls, trainer.cls,
data_collator.cls and training_args.cls are resolved by name against
transformers (and, for collators, micm_nlp.training.data_collators). Adding a new
backbone or head should need no change to this package. Where a class needs an
unusual keyword argument, prefer the passthrough dictionaries — model.pretrained.args
and tokenizer.args are splatted verbatim into the constructor — over new code.
Note
Scientific notation works without a decimal point. PyYAML’s SafeLoader follows
YAML 1.1, where 5e-5 parses as a string; micm_nlp.config widens the float
resolver once at import, so learning_rate: 5e-5 is a float everywhere.
Top-level sections¶
Section |
Purpose |
|---|---|
|
|
|
Task identity, metric groups, prediction post-processing rules |
|
PEFT method and its hyperparameters |
|
Architecture tag, pretrained source, adapter, or from-scratch init |
|
Tokenizer source and behaviour |
|
Dataset location, input/label keys, preprocessing and tokenization rules |
|
When to evaluate (before/during/after training), per-task grouping |
|
Whether to run the test split, zero-shot behaviour, prediction saving |
|
Which HuggingFace |
|
Which HuggingFace |
|
Which collator to instantiate, plus its kwargs |
|
Behaviour this package adds on top of HuggingFace |
|
|
|
Environment variables set at config-load time |
peft¶
All Cross-Prompt Encoder variants use peft_type: XPE and differ only in
encoder_ratio — the fraction of virtual tokens that are cross-prompt encoded.
|
Variant |
Behaviour |
|---|---|---|
|
SPT |
Plain soft prompt tuning, no reparameterization |
|
XPE |
All virtual tokens pass through the encoder head |
|
DUAL |
Concatenation of both; the ratio is a free hyperparameter |
peft:
peft_type: XPE
task_type: CAUSAL_LM
num_virtual_tokens: 20
encoder_reparameterization_type: MLP
encoder_hidden_size: 256
encoder_num_layers: 2
encoder_dropout: 0.1
encoder_ratio: 1
PEFT.setup_model() routes to the Cross-Prompt Encoder path or to stock PEFT
depending on this block. Checkpoints written before the XPE peft_type existed
(P_TUNING plus an encoder_ratio) still load.
custom_training_args¶
The knobs this package adds beyond HuggingFace’s TrainingArguments.
Key |
Type |
Meaning |
|---|---|---|
|
float |
Fraction of training before stopping may trigger |
|
int |
Evaluations without improvement before stopping |
|
float |
Minimum improvement that counts |
|
str |
Metric to monitor — see below |
|
int | |
Token-budget batching for evaluation |
|
int | |
Token-budget batching for the test split |
|
bool |
Force a sequential sampler for that stage |
|
bool |
Save the final model after training |
|
bool |
Discard intermediate checkpoints |
|
list[str] |
Extra dataset columns to keep past |
|
list |
Per-parameter-group learning rate and weight decay |
|
bool |
Batch sampler that holds out a random task |
|
list[str] |
Restrict generation to these strings |
early_stopping_metric¶
Early stopping is decoupled from best-checkpoint selection.
Value |
Effect |
|---|---|
|
Delegate to |
any literal key, e.g. |
Monitor that key directly; direction inferred (a name containing |
unset |
Defaults to |
This matters when the selection metric and the stopping signal should differ — for example selecting on accuracy while the evaluation loss is unstable.
Token-budget batching¶
Instead of a fixed per_device_eval_batch_size, batches can be built to a target
token count. This keeps memory roughly constant across languages whose tokenizations
differ in length by an order of magnitude.
Value |
Behaviour |
|---|---|
|
Fixed |
|
Probe the GPU at runtime for the largest budget that does not run out of memory |
an integer |
Skip the probe and use this budget exactly |
Two constraints are validated at config load:
Mutually exclusive with the matching
*_force_sequentialflag — token-budget mode needs length-sorted batching, which a sequential sampler overrides.Mutually exclusive with HuggingFace’s
LengthGroupedSampler; the token-budget sampler already sorts by length.
Booleans are rejected, and integers must be positive.
Warning
The token-budget sampler yields samples in globally length-sorted order, not dataset
order. Anything zipping predictions against a dataset split must use the sampler’s
order permutation. The package does this internally for per-task grouping and
prediction saving; custom consumers of raw predictions should be aware of it.
optimizer_grouped_parameters¶
Assigns a different learning rate and weight decay to parameters whose names contain given substrings — the mechanism behind giving prompt embeddings their own schedule:
custom_training_args:
optimizer_grouped_parameters:
- param_name_parts:
- dedicated_embeddings
lr: 5.0e-5
weight_decay: 0.01
Parameters that match no group fall back to the global learning_rate and
weight_decay from training_args.
task.preproc_rules¶
Post-processing applied to predictions before metrics.
Key |
Meaning |
|---|---|
|
Flatten predictions and labels before metric computation |
|
Drop padded positions |
|
Convert between label ids and names |
|
Normalise label names before comparison |
|
Assert predictions and labels line up |
|
Produce a confusion matrix |
|
Axis for the argmax (default |
|
Restrict the answer-slot argmax to the candidate tokens in |
label_restricted_likelihood implements lm-eval-harness multiple_choice scoring
for mcqa_ftp: rather than taking a full-vocabulary argmax at the answer position,
only the configured label tokens compete. It is opt-in and off by default.
A complete example¶
examples/configs/xsc_finetune.yml fine-tunes BLOOM-560M with the Cross-Prompt
Encoder on the Arabic split of FTP-reframed XStoryCloze:
mode: finetune
task:
category: text_generation
name: mcqa_ftp
metric_groups:
- metrics:
- accuracy
preproc_rules:
flatten: true
filter_padded: true
verify_labels_match: true
peft:
peft_type: XPE
task_type: CAUSAL_LM
num_virtual_tokens: 20
encoder_reparameterization_type: MLP
encoder_hidden_size: 256
encoder_num_layers: 2
encoder_dropout: 0.1
encoder_ratio: 1
model:
architecture: bloom
pretrained:
cls: AutoModelForCausalLM
name: bigscience/bloom-560m
source: huggingface
tokenizer:
source: huggingface
name: bigscience/bloom-560m
args:
padding_side: right
ds:
category: benchmarks
dirs: mikaberidze/xstory-cloze-ftp
name: ar
type: huggingface
comes_with_splits:
train: eval
test: false
validation: train
input:
key: text
standardize_key: true
label:
key: answer_label
standardize_key: true
trainer:
cls: Trainer
training_args:
cls: TrainingArguments
args:
num_train_epochs: 10
learning_rate: 5.0e-5
metric_for_best_model: accuracy
greater_is_better: true
load_best_model_at_end: true
bf16: true
The full file, including tokenization rules, evaluation schedule and collator settings, is in the repository.