Fix tied embeddings#2237
Open
kunal-vaishnavi wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Python model builder’s tied-embedding initialization logic and adds CI coverage to exercise tied-embedding edge cases via pytest.
Changes:
- Refactors tied-embedding determination in the model builder to compute explicit
tied_quantized_embeddings/tied_unquantized_embeddingsflags and uses them in embedding construction. - Adds a new pytest module to cover shared-embedding configuration permutations (plus a small unit test for
make_matmul_int4behavior). - Updates the Python test runner entrypoint to run the
builder/andmodels/pytest suites as part of the standard pipeline run.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/python/py/models/builders/base.py |
Reworks tied-embedding / quantization eligibility flags and switches embedding logic to use the new tied flags. |
test/python/builder/test_tied_embeddings.py |
Adds unit tests for tied-embedding flag behavior and INT4 MatMul fallback/emit behavior. |
test/python/test_onnxruntime_genai.py |
Expands the invoked pytest targets to include builder/ and models/ test suites. |
Comment on lines
+543
to
+548
| if shared_embeddings: | ||
| self.tied_quantized_embeddings = self.quantized_embeds and self.quantized_lm_head | ||
| self.tied_unquantized_embeddings = not self.tied_quantized_embeddings | ||
| else: | ||
| self.tied_unquantized_embeddings = False | ||
| self.tied_quantized_embeddings = False |
Comment on lines
+127
to
+130
| (True, True, True, False), | ||
| (True, False, False, True), | ||
| (False, True, False, True), | ||
| (False, False, False, True), |
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.
Description
This PR rewrites how tied embeddings are determined in the model builder. It also adds a unit test file to ensure that the different cases for tied embeddings are tested in the CIs.
Motivation and Context
There are still some small edge cases that haven't been validated for tied embeddings.