[Doc] torch.profiler code example broken by missing line break
- Dominant language
- Python
- Stars
- 103k
- Forks
- 29.5k
- PR merge metrics
- PR metrics pending
Description
## Description
In the `torch.profiler` documentation explaining the `schedule` functionality, a missing newline after an inline comment causes the active context manager declaration (`with torch.profiler.profile(`) to be parsed as part of the comment string.
Because the context manager declaration is hidden from the Python interpreter, the subsequent indented blocks lose their parent structure, causing an immediate `IndentationError`.
## Reproduction Script
```python
import torch
def code_iteration_to_profile(iter):
pass
N = 5
# prof.export_chrome_trace("/tmp/test_trace_" + str(prof.step_num) + ".json")with torch.profiler.profile(
activities=[
torch.profiler.ProfilerActivity.CPU,
torch.profiler.ProfilerActivity.CUDA,
],
schedule=torch.profiler.schedule(wait=1, warmup=1, active=2, repeat=1)
) as p:
for iter in range(N):
code_iteration_to_profile(iter)
```
## Actual Output
```
File "", line 10
activities=[
^
IndentationError: unexpected indent
```
## Expected Behavior
There should be a distinct newline separating the comment block from the active code execution block to maintain valid Python structure and execution flow.
## Impact
The code example is completely non-functional upon copy-paste. This leads to developer friction and confusion regarding the required syntax for initializing the profiler context manager.
## Environment
```
PyTorch: 2.13.0
Python: 3.12.13
```
## Suggested Fix
Insert a standard newline / carriage return immediately before the context manager declaration in the documentation format block.
cc @svekars @sekyondaMeta @AlannaBurke
Contributor guide
Research direction
Search the torch.profiler documentation for the schedule example and run the reproduction script from the issue to confirm the IndentationError. Insert the missing newline before the with torch.profiler.profile declaration, then rerun the script and verify that the example parses and executes normally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100