Fix cost model num_bytes for sub-byte weight precisions - #2668
Open
dfedoryshchev wants to merge 1 commit into
Open
dfedoryshchev wants to merge 1 commit into
dfedoryshchev wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped and addresses a concrete failure mode with added regression coverage; remaining feedback is a minor naming nit.
Pull request overview
This PR fixes generate-cost-model output for sub-byte weight precisions (int4/uint4/nf4/fp4) so the generated CSV can be consumed by the CaptureSplitInfo pass without failing integer parsing, improving reliability of downstream flows like auto-opt.
Changes:
- Round
num_bytesup to an integer withmath.ceil(...)when generating the cost model CSV (prevents float values like49250304.0). - Extend the existing test helper to optionally pass
--weight_precision. - Add a regression test that generates cost models for the four sub-byte precisions and asserts numeric columns parse as integers.
File summaries
| File | Description |
|---|---|
olive/cli/generate_cost_model.py |
Uses math.ceil to ensure integer num_bytes are written to the CSV for sub-byte precisions. |
test/passes/pytorch/test_capture_split_info.py |
Adds a regression test verifying cost model CSV numeric columns remain integer-parsable for int4/uint4/nf4/fp4. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
56
to
59
|
|
||
| num_params = sum(p.numel() for p in module.parameters()) | ||
| num_bytes = num_params * PRECISON_TO_BYTES[self.args.weight_precision] | ||
| num_bytes = math.ceil(num_params * PRECISON_TO_BYTES[self.args.weight_precision]) | ||
| if isinstance(module, torch.nn.Linear): |
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.
Describe your changes
olive generate-cost-model -p int4writes a cost model thatCaptureSplitInfocannot read.The byte count comes from
num_params * PRECISON_TO_BYTES[...], and the four sub-byte entries in that table are0.5, so the product is a float and the column is written as49250304.0instead of49250304.CaptureSplitInfo.split_using_cost_modelparses that column withint(), which raisesValueErroron the first data row.ValueErroris inEXCEPTIONS_TO_RAISE, so the run aborts rather than falling back to another split strategy.int4,uint4,nf4andfp4are all argparse choices, and the generate step exits 0 with a success message, so the failure only turns up later inauto-opt.This rounds the byte count up to an integer.
math.ceilrather thanintbecause the value feeds thesplit_bytes + num_bytes > memorycomparison, and a 4-bit layer with an odd parameter count really does occupy the extra half byte. The nine integer-factor precisions are unchanged. The five cost models shipped underolive/assets/cost_models/are integer in every column already, since they were generated at thefp16default, which is probably why this has gone unnoticed.Tests
Adds a regression test that generates a cost model at each of the four sub-byte precisions and asserts the columns parse as integers. It reuses the existing
get_cost_modelhelper and the same tiny model the neighbouring cost-model test uses.One thing I would rather state than tick: I have not been able to run the suite or
lintrunnerlocally, so the new test is unverified on my side and those two boxes are left unchecked.Checklist before requesting a review
lintrunner -agenerate-cost-modelnow writes integer byte counts for sub-byte weight precisions, so the generated cost model is usable byCaptureSplitInfo.