Repository navigation
Add public ExportBackend.Torch that folds weight compression - #154
Merged
NehalBhandari merged 4 commits intoOct 24, 2026
Merged
NehalBhandari merged 4 commits into
NehalBhandari merged 4 commits into
Conversation
NehalBhandari
requested review from
aseemw,
crowbat,
dengqiaoyu,
guru-desh and
u-simha
October 21, 2026 17:19
dengqiaoyu
reviewed
Oct 22, 2026
dengqiaoyu
left a comment
Contributor
There was a problem hiding this comment.
Posting some current comments, will finish the rest later.
dengqiaoyu
approved these changes
Oct 23, 2026
dengqiaoyu
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the changes!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a public
ExportBackend.Torchbackend for fast PyTorch inference, e.g. running evals on a compressed model.finalize(backend=ExportBackend.Torch)folds weight compression into dense weights, so the model no longer reconstructs compressed weights on every forward pass. Activation fake quantization is kept, so outputs match the prepared model.Previously, the only way to evaluate a compressed model in torch was to use the prepared model, which re-applies fake palettization / fake quantization / pruning masks to every weight on every forward pass. The private
ExportBackend._TORCHexisted but returned the prepared model unchanged.Changes
ExportBackend.Torchreplaces the private_TORCH._TORCHstays as a deprecated alias (emitsDeprecationWarning), via the existing__deprecated_aliases__mechanism.KMeansPalettizer,MagnitudePruner, eagerQuantizer): newfold_compression_parametrizationshelper removes the compressor's weight parametrizations withleave_parametrized=True, in eval mode.originalare unparametrized without re-applying the compression.Quantizerwithexecution_mode=graph): newprepare_for_torch_inferencewrites each fake-quantized weight in place and removes its weight fake quantization node and module.finalize; error messages that suggestedExportBackend._TORCHnow suggestExportBackend.Torch.Results
ResNet50, ImageNet validation (50,000 images), A100, batch size 256. Forward time is the mean per batch after warm-up, excluding data loading.
Graph mode already applies conv-BN folding during
finalize(before any backend step). Because of it, graph-mode outputs differ from the prepared model at the fp32-rounding level (~1e-6 on logits); the weight fold itself adds no difference.Qwen3-4B, 4-bit scalar k-means palettization (group size 32), MMLU-Pro 5-shot with chat template, one A100, batch size 8.