loss
Classes
Memory-bounded CE for replicated or vocabulary-TP logits. |
|
TP-aware teacher-to-student Kullback-Leibler divergence. |
|
TP-aware total-variation distance between teacher and student. |
Functions
- class ChunkedCrossEntropy
Bases:
ModuleMemory-bounded CE for replicated or vocabulary-TP logits.
Unlike AutoModel’s generic masked CE, a vocabulary-sharded DTensor remains sharded throughout the calculation. Token chunks bound the fp32 softmax workspace, and checkpointing recomputes that workspace during backward instead of retaining one vocabulary-sized buffer per token.
- __init__(fp32_upcast=True, ignore_index=-100, reduction='sum', chunk_size=0, checkpoint_chunks=False)
- Parameters:
fp32_upcast (bool)
ignore_index (int)
reduction (str)
chunk_size (int)
checkpoint_chunks (bool)
- forward(logits, labels, mask=None, num_label_tokens=None)
- forward_no_checkpoint(logits, labels, num_label_tokens=None)
- class KDLoss
Bases:
_DistributionLossTP-aware teacher-to-student Kullback-Leibler divergence.
- metric: Literal['kld', 'tvd'] = 'kld'
- class TVDLoss
Bases:
_DistributionLossTP-aware total-variation distance between teacher and student.
- metric: Literal['kld', 'tvd'] = 'tvd'
- build_distribution_loss(metric, **kwargs)
- Parameters:
metric (str)
- Return type:
_DistributionLoss