Skip to content

Add option to export phi-3-mini model via buck2 #4189

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

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
get_symmetric_quantization_config,
XNNPACKQuantizer,
)
from torch.export import export

from transformers import Phi3ForCausalLM


def main() -> None:
torch.random.manual_seed(0)

# pyre-ignore: Undefined attribute [16]: Module `transformers` has no attribute `Phi3ForCausalLM`
model = Phi3ForCausalLM.from_pretrained("microsoft/Phi-3-mini-4k-instruct")

example_inputs = (torch.randint(0, 100, (1, 100), dtype=torch.long),)
Expand All @@ -48,8 +48,14 @@ def main() -> None:
model(*example_inputs)
model = convert_pt2e(model, fold_quantize=False)
DuplicateDynamicQuantChainPass()(model)
model = export(
model, example_inputs, dynamic_shapes=dynamic_shape, strict=False
# TODO(lunwenh): update it to use export once
# https://github.com/pytorch/pytorch/issues/128394 is resolved.
model = torch.export._trace._export(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this though? can we still do torch.export.export()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

export currently fails due to pytorch/pytorch#128394. We will use this trick until that issue is fixed.

model,
example_inputs,
dynamic_shapes=dynamic_shape,
strict=False,
pre_dispatch=False,
)

edge_config = get_xnnpack_edge_compile_config()
Expand Down
Loading