Skip to content

Commit 1af3ae4

Browse files
feat: make torch frame count configurable
1 parent 2a99ff9 commit 1af3ae4

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

ddtrace/internal/settings/profiling.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,15 @@ class ProfilingConfigPytorch(DDConfig):
495495
help="How many events the PyTorch profiler records each collection",
496496
)
497497

498+
max_frames = DDConfig.v(
499+
int,
500+
"max_frames",
501+
default=128,
502+
validator=validators.range(1, t.cast(int, float("inf"))),
503+
help_type="Integer",
504+
help="Maximum depth to walk up the cpu_parent chain when reconstructing the operator call tree",
505+
)
506+
498507

499508
class ProfilingConfigException(DDConfig):
500509
__item__ = __prefix__ = "exception"

ddtrace/internal/settings/profiling.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ProfilingConfigHeap(DDConfig):
5252
class ProfilingConfigPytorch(DDConfig):
5353
enabled: bool
5454
events_limit: int
55+
max_frames: int
5556

5657
class ProfilingConfigException(DDConfig):
5758
enabled: bool

ddtrace/profiling/collector/pytorch.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
_NANOS_PER_MICROSECOND = 1e3
2020

21-
# Safety bound on how far we walk up the cpu_parent chain when reconstructing
22-
# the operator call tree, to guard against pathological depths.
23-
_MAX_FRAMES = 128
2421

2522
# Frames require a file name, but GPU frames are not from a Python file.
2623
# We use the following as a placeholder.
@@ -209,7 +206,7 @@ def _handle_torch_trace(prof: Any) -> None:
209206
handle.push_frame(e.name, _FILE_PLACEHOLDER, 0, 0)
210207
parent = getattr(e, "cpu_parent", None)
211208
depth = 0
212-
while parent is not None and depth < _MAX_FRAMES:
209+
while parent is not None and depth < config.pytorch.max_frames:
213210
handle.push_frame(parent.name, _FILE_PLACEHOLDER, 0, 0)
214211
parent = getattr(parent, "cpu_parent", None)
215212
depth += 1

0 commit comments

Comments
 (0)