Skip to content

Commit 8c108ae

Browse files
[python_pytorch] Initial commit
1 parent 33a7007 commit 8c108ae

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.11
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY ./scenarios/python_pytorch_3.11/ /usr/src/app
6+
7+
RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu
8+
RUN pip install --no-cache-dir -r requirements.txt
9+
10+
ENV EXECUTION_TIME_SEC 30
11+
ENV DD_PROFILING_ENABLED true
12+
ENV DD_TRACE_ENABLED false
13+
ENV DD_TRACE_DEBUG false
14+
ENV DD_PROFILING_MEMORY_ENABLED=false
15+
ENV DD_PROFILING_OUTPUT_PPROF="/app/data/profiles"
16+
17+
CMD ddtrace-run python main.py
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"test_name": "python_pytorch",
3+
"stacks": [
4+
{
5+
"profile-type": "cpu-time",
6+
"stack-content": [
7+
{
8+
"regular_expression": "<module>;.*main;.*heavy_compute",
9+
"percent": 66,
10+
"error_margin": 5,
11+
"labels": [
12+
{
13+
"key": "thread name",
14+
"values": [
15+
"MainThread"
16+
]
17+
}
18+
]
19+
},
20+
{
21+
"regular_expression": "<module>;.*main;.*light_compute",
22+
"percent": 33,
23+
"error_margin": 6,
24+
"labels": [
25+
{
26+
"key": "thread name",
27+
"values": [
28+
"MainThread"
29+
]
30+
}
31+
]
32+
}
33+
]
34+
}
35+
],
36+
"scale_by_duration": true
37+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
from time import time
3+
4+
import torch
5+
6+
7+
def light_compute(a: torch.Tensor, b: torch.Tensor) -> None:
8+
for _ in range(20):
9+
torch.mm(a, b)
10+
11+
12+
def heavy_compute(a: torch.Tensor, b: torch.Tensor) -> None:
13+
for _ in range(40):
14+
torch.mm(a, b)
15+
16+
17+
def main() -> None:
18+
torch.set_num_threads(1)
19+
a = torch.randn(300, 300)
20+
b = torch.randn(300, 300)
21+
execution_time_sec = float(os.getenv("EXECUTION_TIME_SEC", "10"))
22+
end = time() + execution_time_sec
23+
while time() < end:
24+
light_compute(a, b)
25+
heavy_compute(a, b)
26+
27+
28+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ddtrace

0 commit comments

Comments
 (0)