modelopt.torch.distill.bypass#

bypass(student, teacher, train_dataloader, config=None, *, validation_dataloader=None, device_mesh=None)#

Optimize IQ native scales on streamed frozen teacher boundary inputs.

Parameters:
  • student (Module) – Existing ModelOpt IQ PTQ model; frozen formats may coexist.

  • teacher (Module) – Separate original-weight callable with matching boundary paths.

  • train_dataloader – Unique sample batches that exactly fill each global update. Dict batches accept boolean/integer valid_mask or loss_mask, in that order, with nonzero meaning valid rather than a token weight. Otherwise, attention_mask must be 2D boolean/integer. Floating or 4D attention masks require an explicit validity mask. Weighted masks are unsupported; other metadata does not define the loss mask. The HF adapter additionally derives default validity from _packed_seq_ids: zero denotes padding and positive IDs identify documents. Explicit loss masks win.

  • config – A BypassConfig, a dict, or None for the established defaults.

  • validation_dataloader – Optional held-out batches for finalized-student valid-token MSE. Diagnostic failures propagate after committing training updates to the student. Zero-step preflight skips validation as well as training.

  • device_mesh – Caller-owned placement mesh, adopted by supported integrations.

Return type:

Module

Finalization commits boundaries in order. Any failure during finalization may leave earlier boundaries committed; reload a saved checkpoint before retrying.

For HF PTQ, use TransformersBypassAdapter.weight_patterns with the same selectors to obtain ordinary ModelOpt weight_quantizer globs before quantizing the student. These patterns exclude frozen routing gates.

Returns:

The supplied student, finalized for ordinary ModelOpt save/export. Temporary fields, hooks, modes and gradient flags are restored on every exit.

Parameters:
  • student (Module)

  • teacher (Module)

Return type:

Module