meta-pytorch / meta-pytorch/autoparallel

Integrate memory tools into default examples

Open
#55 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
97
Forks
27
Avg merge
5d 18h
Merged PRs (30d)
3

Description

I found a diff like this useful for debugging memory problems:

diff --git a/examples/example_llama3.py b/examples/example_llama3.py
index e94f663..4c061d7 100644
--- a/examples/example_llama3.py
+++ b/examples/example_llama3.py
@@ -586,7 +586,7 @@ device = torch.device("cuda")

 def model_fn():
     model_args = TransformerModelArgs(
-        n_layers=8, vocab_size=vocab_size, max_seq_len=seqlen
+        n_layers=2, vocab_size=vocab_size, max_seq_len=seqlen
     )
     m = Transformer(model_args)
     return m
@@ -628,6 +628,8 @@ with AutoParallel(model, input_fn, mesh) as autop:
     parallel_mod = autop.apply_placement(sharding_placement)

 # run weight init on our sharded DTensor params
+torch.cuda.memory._record_memory_history(max_entries=100000)
+
 parallel_mod.to_empty(device="cuda")
 parallel_mod.init_weights()

@@ -643,3 +645,7 @@ x = (
 out = parallel_mod(*x)
 out.backward(torch.randn_like(out))
 print("All good!")
+
+torch.cuda.memory._dump_snapshot("mini_new3.pickle")
+
+print(torch.cuda.memory_summary())

Would be good to actually commit this to all of our examples in some way that's useful for other people.

Contributor guide

Open the contributing guide

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.

Research direction

Start with examples/example_llama3.py and compare the other example files to identify where the memory debugging tools fit consistently. Review the shown memory-history recording, snapshot dump, and memory summary calls, then verify that the examples remain runnable and provide useful memory diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.