callbacks
callbacks
¶
HuggingFace Trainer callbacks for Safe Synthesizer training.
Classes:
| Name | Description |
|---|---|
InferenceEvalCallback |
Trainer callback that performs inference-based evaluation during training. |
ProgressBarCallback |
A |
SafeSynthesizerWorkerCallback |
Trainer callback that emits structured progress logs at a fixed interval. |
InferenceEvalCallback(schema, metadata, processor, num_prompts_per_batch=16, num_batches=None, patience=3, invalid_fraction_threshold=0.8, generate_kwargs=None)
¶
Bases: TrainerCallback
Trainer callback that performs inference-based evaluation during training.
Generates records using the current model and validates them against a
schema. Empirically, the fraction of invalid records generated is a good
indicator of model quality. The callback can stop training early if the
invalid fraction satisfies the stopping criteria specified by
invalid_fraction_threshold and patience.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict
|
Schema to validate the generated records against. |
required |
metadata
|
ModelMetadata
|
Pretrained model metadata (prompt template, instruction, etc.). |
required |
processor
|
Processor
|
Record processor used to parse and validate generated text. |
required |
num_prompts_per_batch
|
int
|
Number of prompts per batch. |
16
|
num_batches
|
Optional[int]
|
Number of batches to generate. |
None
|
invalid_fraction_threshold
|
float
|
The fraction of invalid records that will
stop generation after the |
0.8
|
patience
|
int
|
Number of consecutive generations where the
|
3
|
generate_kwargs
|
dict | None
|
Keyword arguments to pass to the model's generate method. |
None
|
Methods:
| Name | Description |
|---|---|
on_evaluate |
Generate records with the current model and optionally stop training. |
Source code in src/nemo_safe_synthesizer/training/callbacks.py
on_evaluate(args, state, control, **kwargs)
¶
Generate records with the current model and optionally stop training.
Runs inference for num_batches batches, validates each against
the schema, and sets control.should_training_stop if the invalid
record fraction exceeds the threshold for patience consecutive
evaluations.
Source code in src/nemo_safe_synthesizer/training/callbacks.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
ProgressBarCallback()
¶
SafeSynthesizerWorkerCallback(log_interval=60.0)
¶
Bases: TrainerCallback
Trainer callback that emits structured progress logs at a fixed interval.
Logs are written via the logger.runtime channel as rendered tables
containing epoch, step, loss, and progress fraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_interval
|
float
|
Minimum seconds between successive log emissions. |
60.0
|