-
Notifications
You must be signed in to change notification settings - Fork 482
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
When profile_memory, also export and save the snapshot.pickle for lora_finetune_single_device.py #1382
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/1382
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit e797f3b with merge base 3c580fc (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this! Can you fix the linter complaints? After that this should be good to go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ebsmothers, wdyt? We were missing the memory snapshot. My only concern is hardcoding torch.cuda if we plan to support xpu
Edit: you already approved it :P
@@ -579,6 +584,9 @@ def train(self) -> None: | |||
): | |||
break | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Memory profiling | |
if curr_epoch == 0 and self.profiler_profile_memory and idx == (self.profiler_wait_steps + self.profiler_warmup_steps): | |
torch.cuda.memory._record_memory_history() |
@@ -579,6 +584,9 @@ def train(self) -> None: | |||
): | |||
break | |||
|
|||
if curr_epoch == 0 and self.profiler_profile_memory and idx == self.profiler_wait_steps + self.profiler_warmup_steps: | |||
torch.cuda.memory._record_memory_history() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is if in the future we support other backend, like intel. It makes me think that this should be a function, instead of being hardcoded as "torch.cuda"
cc: @ebsmothers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is if in the future we support other backend, like intel. It makes me think that this should be a function, instead of being hardcoded as "torch.cuda"
cc: @ebsmothers
I think it's OK, idk that memory snapshot would be supported on XPU anyways. We can do a check on device + profile_memory combo just to be safe though
@@ -626,6 +634,9 @@ def train(self) -> None: | |||
num_tokens = 0 | |||
t0 = time.perf_counter() | |||
|
|||
if curr_epoch == 0 and self.profiler_profile_memory and idx == self.profiler_wait_steps + self.profiler_warmup_steps + self.profiler_active_steps: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if curr_epoch == 0 and self.profiler_profile_memory and idx == self.profiler_wait_steps + self.profiler_warmup_steps + self.profiler_active_steps: | |
# Stop memory profiling | |
if curr_epoch == 0 and self.profiler_profile_memory and idx == self.profiler_wait_steps + self.profiler_warmup_steps + self.profiler_active_steps: |
should we just delete the HTML to save time, since it takes a while to save? Or is it useful? |
@@ -328,6 +328,11 @@ def _setup_profiler( | |||
|
|||
log.info(f" Profiler config after instantiation: {profiler_cfg}") | |||
|
|||
self.profiler_wait_steps = profiler_cfg["wait_steps"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be throwing an error in our recipe tests, can you just quickly inspect profiler_cfg
after running e.g.
pytest tests/recipes/test_lora_finetune_single_device.py -m integration_test -k 'test_loss'
I thought these fields would be defined based on this, but seems like something weird is happening here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it's because profiling isn't enabled for tests, so it returns here
torchtune/torchtune/utils/_profiler.py
Line 262 in 2f8ed7a
return DummyProfiler(), DictConfig({"enabled": False}) |
Writing the html is very light so it doesn't make a tangible difference, I'm not sure if people are using it today so it'd be bad to just remove it if there were actual users. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1382 +/- ##
==========================================
- Coverage 72.57% 70.56% -2.01%
==========================================
Files 271 272 +1
Lines 12736 12895 +159
==========================================
- Hits 9243 9100 -143
- Misses 3493 3795 +302 ☔ View full report in Codecov by Sentry. |
@janeyx99 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Context
What is the purpose of this PR? Is it to
Please link to any issues this PR addresses.
Changelog
What are the changes made in this PR?
Previously, you only had the html from the profiler, which is not interactive:
Now, you get that in addition to:
Test plan
Please make sure to do each of the following if applicable to your PR. (If you're not sure about any one of these just ask and we will happily help. We also have a contributing page for some guidance on contributing.)
pre-commit install
)pytest tests
pytest tests -m integration_test
UX
If your function changed a public API, please add a dummy example of what the user experience will look like when calling it.
Example of docstring:
torchtune/torchtune/modules/vision_transformer.py
Line 285 in 6a7951f
Example in our docs: https://pytorch.org/torchtune/main/tutorials/qat_finetune.html#applying-qat-to-llama3-models