Skip to content

[PyTorch] Add user_metadata display to memory visualizer#165939

Closed
sraikund16 wants to merge 1 commit intopytorch:mainfrom
sraikund16:export-D85095152
Closed

[PyTorch] Add user_metadata display to memory visualizer#165939
sraikund16 wants to merge 1 commit intopytorch:mainfrom
sraikund16:export-D85095152

Conversation

@sraikund16
Copy link
Contributor

@sraikund16 sraikund16 commented Oct 20, 2025

Summary: Enhanced the PyTorch CUDA memory visualizer to display user_metadata alongside stack frames when inspecting allocations. The user_metadata field is now shown in all views (Allocator State History, Active Memory Timeline, etc.) with consistent formatting. The implementation handles both string and object metadata types, displaying strings directly and objects as key-value pairs.

Test Plan:

  1. Generate a memory snapshot with user_metadata
  2. Open the memory visualizer in a browser
  3. Load the snapshot file
  4. Verify user_metadata appears
  5. Test with both string metadata ("testing") and object metadata ({"key": "value"})
  6. Verify formatting shows "User Metadata:\n " for strings

{F1982860439}

Differential Revision: D85095152

Summary: Enhanced the PyTorch CUDA memory visualizer to display user_metadata alongside stack frames when inspecting allocations. The user_metadata field is now shown in all views (Allocator State History, Active Memory Timeline, etc.) with consistent formatting. The implementation handles both string and object metadata types, displaying strings directly and objects as key-value pairs.

Test Plan:
1. Generate a memory snapshot with user_metadata:
   ```python
   import torch
   torch.cuda.memory._record_memory_history(enabled=True)
   # Add allocations with user_metadata
   x = torch.randn(1000, 1000, device='cuda')
   torch.cuda.memory._dump_snapshot("snapshot.pickle")
   ```
2. Open the memory visualizer in a browser
3. Load the snapshot file
4. Verify user_metadata appears
5. Test with both string metadata ("testing") and object metadata ({"key": "value"})
6. Verify formatting shows "User Metadata:\n  <value>" for strings

 {F1982860439}

Differential Revision: D85095152
@pytorch-bot
Copy link

pytorch-bot bot commented Oct 20, 2025

🔗 Helpful Links

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

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

✅ No Failures

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

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

@meta-codesync
Copy link

meta-codesync bot commented Oct 20, 2025

@sraikund16 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D85095152.

@yushangdi
Copy link
Contributor

Thanks! Can you add a screenshot to the output? (I guess {F1982860439} might be the intention to add a screenshot?)

@sraikund16
Copy link
Contributor Author

Thanks! Can you add a screenshot to the output? (I guess {F1982860439} might be the intention to add a screenshot?)

It is in the diff D85095152. Didn't post it here since I tested on a real workload.

@sraikund16 sraikund16 added enhancement Not as big of a feature, but technically not a bug. Should be easy to fix release notes: profiler release notes category labels Oct 21, 2025
@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 21, 2025
@sraikund16
Copy link
Contributor Author

@pytorchbot merge

@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

zhudada0120 pushed a commit to zhudada0120/pytorch that referenced this pull request Oct 22, 2025
)

Summary: Enhanced the PyTorch CUDA memory visualizer to display user_metadata alongside stack frames when inspecting allocations. The user_metadata field is now shown in all views (Allocator State History, Active Memory Timeline, etc.) with consistent formatting. The implementation handles both string and object metadata types, displaying strings directly and objects as key-value pairs.

Test Plan:
1. Generate a memory snapshot with user_metadata
2. Open the memory visualizer in a browser
3. Load the snapshot file
4. Verify user_metadata appears
5. Test with both string metadata ("testing") and object metadata ({"key": "value"})
6. Verify formatting shows "User Metadata:\n  <value>" for strings

 {F1982860439}

Differential Revision: D85095152

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

Labels

ciflow/trunk Trigger trunk jobs on your pull request enhancement Not as big of a feature, but technically not a bug. Should be easy to fix fb-exported Merged meta-exported release notes: profiler release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants