[FX] HopSchema pickle round-trip drops Python metadata

Open Beginner friendly
#207,247 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, pytorch
Domain
backend

Research direction

Start with HopSchema and its inherited FunctionSchema pickle protocol, then inspect test/fx/test_graph_pickler.py and the two named TestHopSchemaPickle tests. Run those tests on CPU to confirm the missing Python attributes. Done means a pickle round-trip restores is_vararg, is_varret, and tree_spec for schemas both with and without arguments.

Written by the indexing model from the issue text.

Description

bot-triaged module: higher order operators module: pickle module: pt2-dispatcher oncall: pt2 triaged

After a standard-library pickle serialization/deserialization round-trip, HopSchema retains its C++ schema but loses the Python attributes is_vararg, is_varret, and tree_spec.

The restored object is still a HopSchema and compares equal to the original schema, but vars(restored) is {}. The inherited FunctionSchema pickle protocol saves only the schema string and does not restore the Python instance fields.

Reproduction baseline: PyTorch main at 26b9b973b2a2dcde7c56036e7d8143eb0f0d8e9d, using a CPU build. No GPU execution is required.

Unit Tests

Both existing tests reproduce the defect:

python -m pytest -v -s \
  test/fx/test_graph_pickler.py::TestHopSchemaPickle::test_hop_schema_pickle_roundtrip

python -m pytest -v -s \
  test/fx/test_graph_pickler.py::TestHopSchemaPickle::test_hop_schema_pickle_with_arguments
  • test_hop_schema_pickle_roundtrip verifies the type, name, and Python metadata of a schema with no arguments or returns.
  • test_hop_schema_pickle_with_arguments verifies a schema with arguments, returns, and variadic flags.

Before the fix, both tests fail.

Error Message

The first test fails at:

self.assertEqual(unpickled.is_vararg, False)

The second test fails at the corresponding assertion:

self.assertEqual(unpickled.is_vararg, True)

Both failures report:

AttributeError: 'HopSchema' object has no attribute 'is_vararg'

This is a missing Python attribute, not a loss of the C++ variadic flags. The Python attributes is_varret and tree_spec are also absent, but each test stops at its first failing metadata assertion.

cc @chauhang @penguinwu @ydwu4 @bdhirsh @bobrenjc93 @aorenste

Dominant language
Python
Stars
106k
Forks
30.7k
Avg merge
30m
Merged PRs (30d)
6

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pytorch/pytorch

All issues in pytorch/pytorch

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.