Repository navigation
BitEmbedding: the bit-bias embedding as a plain module - #14
Merged
Merged
Conversation
PatchedBitEmbeddings wraps a HF model's embeddings behind a tieable façade weight, refreshed by hooks. Models that own their embeddings (WeLT on Megatron) and torch.compile need the same math as a plain module: a table plus a zero-initialized projection of each byte's bits, with folded_weight() as the equivalent table for export. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015Xm62qoeaTunFSU5GYCQ1f
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e5377cd. Configure here.
| assert weight.shape[0] == 256, "Expected a byte-level embedding table (256 rows)." | ||
| self.weight = nn.Parameter(weight.detach().clone()) | ||
| self.bit_proj = nn.Parameter(torch.zeros(weight.shape[1], 8, dtype=weight.dtype)) | ||
| self.register_buffer("bits", unpack_bits(torch.arange(256, dtype=torch.uint8)), persistent=False) |
There was a problem hiding this comment.
Mixed devices in BitEmbedding init
Medium Severity
BitEmbedding clones weight onto that tensor's device but allocates bit_proj and the bits buffer on the default device. A non-CPU table therefore leaves the module split across devices, and folded_weight only casts dtype, so the first forward raises.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit e5377cd. Configure here.
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.


BitEmbedding: the bit-bias embedding as a plain module
PatchedBitEmbeddingsputs the bit-bias (a byte table plus a zero-initialized projection of each byte's 8 bits) behind a tieable façade weight, refreshed by hooks, to patch HF models' embeddings.WeLT on Megatron-Bridge owns its byte embeddings (no HF tying) and runs under
torch.compile, so it uses the same math as a plain module.BitEmbeddingmoves that module here, so WeLT can import it instead of keeping its own copy (sign/WeLTByteEmbedding):BitEmbedding(weight): the table, initialized fromweight, plusbit_proj.folded_weight(): the equivalent plain table, e.g. to export to inference engines.Tests
A new test checks that the embedding starts as its table, that both parameters get gradients, and that the bits are folded into the table correctly. All 14 byte-embedding tests pass, and ruff is clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_015Xm62qoeaTunFSU5GYCQ1f
Note
Low Risk
Additive API and tests only; existing patched HF embedding path is untouched.
Overview
Adds
BitEmbedding, a hook-free variant of the byte bit-bias embedding used byPatchedBitEmbeddings, so stacks like Megatron that own embeddings and usetorch.compilecan use the same math without the tieable façade and refresh hooks.The module keeps a 256×D table plus a zero-initialized D×8
bit_proj, folds bits into the table viafolded_weight(), and looks up withF.embedding.PatchedBitEmbeddingsand HF patching are unchanged.A new unit test checks identity with the initial table, gradients on both parameters, and correct folding when
bit_projis non-zero.Reviewed by Cursor Bugbot for commit e5377cd. Bugbot is set up for automated code reviews on this repo. Configure here.