Skip to content

Bump torchao pin, adjust llama export to support pre-quantization via quantize_ (phi4-mini load/export) #10142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 17, 2025

Conversation

metascroy
Copy link
Contributor

@metascroy metascroy commented Apr 14, 2025

This makes changes to ET so that phi-4 checkpoints saved with:

linear_config = Int8DynamicActivationIntxWeightConfig(
    weight_dtype=torch.int4,
    weight_granularity=PerGroup(32),
    weight_mapping_type=MappingType.SYMMETRIC,
    weight_zero_point_domain=ZeroPointDomain.NONE,
)

can load into ET and export and lower to XNNPACK.

cc @mcr229 for XNNPACK changes. The require changes are if ZeroPointDomain is NONE, then the zero_point is serialized as None, rather than a tensor of zeros.

cc @jackzhxng for phi4-mini changes

Output of phi4 model in ExecuTorch with above quantization:

A California roll is a type of sushi roll that originated in California. It's a variation of the traditional sushi roll, adapted to American preferences and ingredients.

In a classic California roll, you would generally find a combination of ingredients wrapped in a seaweed wrap (nori). Some common ingredients included in a California roll are:

1. Cucumber (or a similar vegetable like a jicama or an English cucumber for a less watery texture)
2. Avocado (for a creamier texture and a slightly milder flavor)
3. Smoked or grilled salmon (or another type

Copy link

pytorch-bot bot commented Apr 14, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/10142

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 74a6aee with merge base cd72ec0 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 14, 2025
Copy link
Contributor

@jackzhxng jackzhxng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good on et side, few comments

output_dir=".",
model_type="PHI4",
)
if os.path.isdir(input_dir_or_checkpoint):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an comment somewhere explicitly detailing that:

  1. FullModelHFCheckpointer is for directory (which would be straight from HF)
  2. phi_4_hf_to_meta is used for single checkpoint, and the use case is for prequantized checkpoints

@@ -257,6 +258,9 @@ def __init__(self, **kwargs):
strict=False,
assign=True,
) # self.model_ = Transformer(gptconf)
for param in self.model_.parameters():
if isinstance(param, TorchAOBaseTensor):
param.requires_grad = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think might as well requires_grad = False across the board, not just for TorchAOBaseTensor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if on-device training stuff might not want that

Copy link
Contributor

@mcr229 mcr229 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XNNPACK parts look ok

@metascroy metascroy requested a review from GregoryComer as a code owner April 16, 2025 02:53
@metascroy metascroy changed the title Updates make phi4-mini load/export with torchao subclass Bump torchao pin, adjust llama export to support pre-quantization via quantize_ (phi4-mini load/export) Apr 16, 2025
@metascroy
Copy link
Contributor Author

Fixing compile issues here: pytorch/ao#2063

@facebook-github-bot
Copy link
Contributor

@metascroy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@metascroy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@metascroy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@metascroy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot merged commit ef99fff into main Apr 17, 2025
92 checks passed
@facebook-github-bot facebook-github-bot deleted the phi4-export branch April 17, 2025 23:01
keyprocedure pushed a commit to keyprocedure/executorch that referenced this pull request Apr 21, 2025
… quantize_ (phi4-mini load/export)

Differential Revision: D73147002

Pull Request resolved: pytorch#10142
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants