KEMBAR78
Enhance "from_node" node meta to track source recursively by yushangdi · Pull Request #142066 · pytorch/pytorch · GitHub
Skip to content

Conversation

@yushangdi
Copy link
Contributor

@yushangdi yushangdi commented Dec 4, 2024

Summary:
Change the "from_node" node meta format to be able to track the provenance of nodes recursively.

The new "from_node" format is a a list node NodeSource:

class NodeSource:
	self.node_name: str
	self.target: str
	self.graph_id: int
	self.pass_name: str
	self.action: str
	self.from_node: List[NoedSource]

This is in preparation for the inductor provenance tracking. For background, the inductor provenance tracking doc: https://docs.google.com/document/d/1dGh9myqNhywmbfP0Quzx_f04bghDFlj8cawj8MopiO8/edit?fbclid=IwZXh0bgNhZW0CMTEAAR0jUQ0Tf4ROLDED8Y_eIzrU0KVZVdRmyIQLp-avt-kGRPI_VgYVNyjH_q0_aem_HCQ_pxHDiwOkO9mQyWB2-g&tab=t.0 (internal only),

Test Plan:

buck2 run 'fbcode//mode/dev-nosan' fbcode//caffe2/test:test_export -- -r test_unflatten_multiple_graphs_state
buck run mode/dev-nosan caffe2/test:fx -- -r node_source

Differential Revision: D66737916

cc @ezyang @SherlockNoMad @EikanWang @jgong5 @wenzhe-nrv @voznesenskym @penguinwu @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang @aakhundov

@pytorch-bot
Copy link

pytorch-bot bot commented Dec 4, 2024

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (2 Unrelated Failures)

As of commit 448eb8d with merge base 960a81f (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

yushangdi added a commit to yushangdi/pytorch that referenced this pull request Dec 4, 2024
…2066)

Summary:

Change the "from_node" node meta format to be able to track the provenance of nodes recursively.

The new "from_node" format is a a list node NodeSource. The old "from_node" is a list of tuples `(node.name, node.target)`

```
class NodeSource:
	self.node_name: str
	self.target: str
	self.graph_id: int
	self.pass_name: str
	self.action: str
	self.from_node: List[NodeSource]
```


We also add a "pass_name" field to indicate which pass created the node from the source. For now the "pass_name" is only used in fx.Interpreter.

These changes will be used for the inductor provenance tracking.

Test Plan:
```
buck2 run 'fbcode//mode/dev-nosan' fbcode//caffe2/test:test_export -- -r test_unflatten_multiple_graphs_state
buck run mode/dev-nosan caffe2/test:fx -- -r node_source
```

Differential Revision: D66737916
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to have an enum here for action?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed now!

Copy link
Contributor

Choose a reason for hiding this comment

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

why not just name?

Copy link
Contributor Author

@yushangdi yushangdi Dec 5, 2024

Choose a reason for hiding this comment

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

why not just name?

@avikchaudhuri I could also just make it name. Just there's also a "pass_name". So I thought it might be good to specify that there are two types of names explicitly, node_name and pass_name.

Also node_name might not be available. In inductor (will be added in follow-up Diffs), sometimes we don't have a specific node source, but only pass_name. For example, in some graph pass (not an Interpreter pass, but a pre_grad or post_grad inductor graph pass), we made some changes. We might not know what is the specific source node, but at least we know which pass added this node. So node_name might be empty.

Do you think just name is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. Also if the node specific info is missing I wonder if it would be better to add another level of indirection instead of filling in defaults like -1, "", etc .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the node specific info is missing I wonder if it would be better to add another level of indirection instead of filling in defaults like -1, "", etc .

@avikchaudhuri Do you mean, something like this?

class NodeInfo:
    def __init__(self, name: str, target: str, graph_id: int):
        self.name = name
        self.target = target
        self.graph_id = graph_id
class NodeSource:
    pass_name: str
    action: Optional["NodeSourceAction"]
    from_node: List["NodeSource"]
    node_info: Optional[NodeInfo]

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of letting node be optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comment above. Sometimes we don't know the source node, we just know a source pass.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feels a bit arbitrary? In any case I'd probably keep indent = 0, 1, ... and multiply by 4 when creating the string so that you can guard on the level instead of 4 x level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed now!

@pytorch-bot pytorch-bot bot added the release notes: quantization release notes category label Dec 5, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

Copy link
Contributor

@avikchaudhuri avikchaudhuri left a comment

Choose a reason for hiding this comment

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

Nits

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Dec 9, 2024
…2066)

Summary:

Change the "from_node" node meta format to be able to track the provenance of nodes recursively.

The new "from_node" format is a a list node NodeSource. The old "from_node" is a list of tuples `(node.name, node.target)`

```
class NodeSource:
    class NodeInfo:
        def __init__(self, name: str, target: str, graph_id: int):
            self.name = name
            self.target = target
            self.graph_id = graph_id

    pass_name: str
    action: Optional["NodeSourceAction"]
    from_node: List["NodeSource"]
    node_info: Optional["NodeInfo"]
```


We also add a "pass_name" field to indicate which pass created the node from the source. For now the "pass_name" is only used in fx.Interpreter.

These changes will be used for the inductor provenance tracking.

Test Plan:
```
buck2 run 'fbcode//mode/dev-nosan' fbcode//caffe2/test:test_export -- -r test_unflatten_multiple_graphs_state
buck run mode/dev-nosan  fbcode//caffe2/test:fx -- -r node_source
buck run mode/dev-nosan  fbcode//caffe2/test:fx -- -r graph_provenance
buck run mode/dev-nosan  fbcode//caffe2/test/quantization:test_quantization -- -r test_simple_metadata_porting
```

Reviewed By: avikchaudhuri

Differential Revision: D66737916
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D66737916

@yushangdi
Copy link
Contributor Author

@pytorchbot merge -i

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: inductor-rocm / rocm6.2-py3.10-inductor / test (inductor, 1, 2, linux.rocm.gpu.2), inductor-rocm / rocm6.2-py3.10-inductor / test (inductor, 2, 2, linux.rocm.gpu.2)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@facebook-github-bot
Copy link
Contributor

@pytorchbot merge

(Initiating merge automatically since Phabricator Diff has merged)

@pytorchmergebot
Copy link
Collaborator

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command
For more information see pytorch-bot wiki.

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

mori360 pushed a commit to mori360/pytorch that referenced this pull request Dec 11, 2024
…2066)

Summary:
Change the "from_node" node meta format to be able to track the provenance of nodes recursively.

The new "from_node" format is a a list node NodeSource:

```
class NodeSource:
	self.node_name: str
	self.target: str
	self.graph_id: int
	self.pass_name: str
	self.action: str
	self.from_node: List[NoedSource]
```

This is in preparation for the inductor provenance tracking. For background, the inductor provenance tracking doc: https://docs.google.com/document/d/1dGh9myqNhywmbfP0Quzx_f04bghDFlj8cawj8MopiO8/edit?fbclid=IwZXh0bgNhZW0CMTEAAR0jUQ0Tf4ROLDED8Y_eIzrU0KVZVdRmyIQLp-avt-kGRPI_VgYVNyjH_q0_aem_HCQ_pxHDiwOkO9mQyWB2-g&tab=t.0 (internal only),

Test Plan:
```
buck2 run 'fbcode//mode/dev-nosan' fbcode//caffe2/test:test_export -- -r test_unflatten_multiple_graphs_state
buck run mode/dev-nosan caffe2/test:fx -- -r node_source
```

Differential Revision: D66737916

Pull Request resolved: pytorch#142066
Approved by: https://github.com/avikchaudhuri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants