distillation_provider
Noise-embedding distillation provider for Megatron-Bridge.
NoiseDistillationProvider adapts Megatron-Bridge's ModelOpt distillation
flow for Stained Glass noise training: the student is wrapped in
MegatronNoisyModel, the teacher is
the clean model, the KD criterion set gains a
MegatronNoiseEmbeddingLoss term (Slot 1),
and the losses are combined by
FixedWeightedKDLossBalancer
(Slot 2 = ModelOpt's logits KL loss).
The provider is grafted onto the student provider's real class at runtime by
convert_to_noise_distillation_provider (it must not be instantiated
directly), mirroring Megatron-Bridge's own convert_to_distillation_provider.
Classes:
| Name | Description |
|---|---|
NoiseDistillationProvider |
Noise-embedding distillation provider built on top of ModelOpt KD. |
Functions:
| Name | Description |
|---|---|
convert_to_noise_distillation_provider |
Graft |
NoiseDistillationProvider
dataclass
¶
Bases: DistillationProvider
Noise-embedding distillation provider built on top of ModelOpt KD.
Subclasses DistillationProvider so that distill()'s
isinstance(config.model, DistillationProvider) check passes and the
to_cfg_dict/__post_init__/__setattr__ behavior is inherited. Like
its parent, the class is grafted onto the student provider's real class at
runtime via convert_to_noise_distillation_provider; it must not be
instantiated directly.
Methods:
| Name | Description |
|---|---|
__init__ |
Reject direct instantiation. |
provide |
Build the distillation model: noisy student + clean teacher + criteria. |
__init__
¶
Reject direct instantiation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Ignored. |
()
|
|
Any
|
Ignored. |
{}
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always; use
|
provide
¶
provide(
pre_process: Any = None,
post_process: Any = None,
vp_stage: Any = None,
) -> Any
Build the distillation model: noisy student + clean teacher + criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Whether this stage runs the pre-process (embedding) step. |
None
|
|
Any
|
Whether this stage runs the post-process (output) step. |
None
|
|
Any
|
The virtual pipeline stage; unsupported (must be |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The ModelOpt distillation model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
convert_to_noise_distillation_provider
¶
convert_to_noise_distillation_provider(
student_provider: GPTModelProvider,
teacher_provider: GPTModelProvider,
*,
std_scale: tuple[float, float],
std_init_shift: float,
std_shallow: float = 1.0,
mean_bound: float | None = None,
mean_init_shift: float = 0.0,
kd_config: Any | None = None,
noise_teacher_layer: str = "embedding",
loss_config: (
MegatronDistillationLossConfig | None
) = None,
kd_logits_weight: float = 1.0,
kd_intermediate_weight: float = 1.0,
kd_original_loss_weight: float = 1.0
) -> NoiseDistillationProvider
Graft NoiseDistillationProvider onto a student provider in place.
Mirrors Megatron-Bridge's convert_to_distillation_provider but keeps
DistillationProvider in the base tuple so isinstance(model,
DistillationProvider) holds, while __bases__[0] remains the student's real
provider class (so _super_class.provide builds the clean student).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
GPTModelProvider
|
The student model provider (mutated in place). |
required |
|
GPTModelProvider
|
The teacher (clean) model provider. |
required |
|
tuple[float, float]
|
Asymptotic |
required |
|
float
|
Shift added to the std estimator's raw output before the tanh
(required); a negative value starts the std field near |
required |
|
float
|
Temperature of the std parameterization's tanh. |
1.0
|
|
float | None
|
Magnitude bound of the mean field, or |
None
|
|
float
|
Shift added to the mean estimator's raw output (only applied
when |
0.0
|
|
Any | None
|
The ModelOpt distillation config. |
None
|
|
str
|
The teacher-side layer the noise criterion pairs with. |
'embedding'
|
|
MegatronDistillationLossConfig | None
|
The noise-embedding loss weights. |
None
|
|
float
|
Weight on the logits KL loss. |
1.0
|
|
float
|
Weight on the intermediate (noise) loss. |
1.0
|
|
float
|
Weight on the student's original task loss. |
1.0
|
Returns:
| Type | Description |
|---|---|
NoiseDistillationProvider
|
The mutated |