Skip to content
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

Read from constants if it exists #6510

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion test/stablehlo/test_export_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def test_llama_export(self):
arg = (torch.randint(0, 1000, (8, 100)), torch.arange(0, 100), None)
options = StableHLOExportOptions()
options.override_tracing_arguments = arg
exported = torch.export.export(model, arg)
with torch.no_grad():
exported = torch.export.export(model, arg)
with tempfile.TemporaryDirectory() as tempdir:
save_as_stablehlo(exported, tempdir, options)

Expand Down
6 changes: 6 additions & 0 deletions torch_xla/stablehlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ def _exported_program_to_stablehlo_bundle(exported_model,
param_and_buffer_keys = exported_model.graph_signature.parameters + exported_model.graph_signature.buffers
state_dict = pytree.tree_map_only(torch.Tensor, lambda x: x.to(device=device),
exported_model.state_dict)

if (constants := getattr(exported_model, 'constants')) is not None:
state_dict.update(
pytree.tree_map_only(torch.Tensor, lambda x: x.to(device=device),
constants))

param_buffer_values = (state_dict[key] for key in param_and_buffer_keys)

if hasattr(exported_model.graph_signature, "lifted_tensor_constants"):
Expand Down
2 changes: 1 addition & 1 deletion torch_xla/tf_saved_model_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def inner(*args):
call_args = stablehlo._extract_call_parameters(args, func.meta, bundle)
return tfxla.call_module(
tuple(call_args),
version=5,
version=6,
Tout=Touts, # dtype information
Sout=Souts, # Shape information
function_list=[],
Expand Down
Loading