File: test_inductor_annotations.py

package info (click to toggle)
pytorch-cuda 2.6.0%2Bdfsg-7
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 161,620 kB
  • sloc: python: 1,278,832; cpp: 900,322; ansic: 82,710; asm: 7,754; java: 3,363; sh: 2,811; javascript: 2,443; makefile: 597; ruby: 195; xml: 84; objc: 68
file content (41 lines) | stat: -rw-r--r-- 1,258 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Owner(s): ["module: inductor"]
import torch
import torch._inductor.config as inductor_config
from torch._inductor.test_case import run_tests, TestCase
from torch._inductor.utils import run_and_get_code
from torch.testing._internal.triton_utils import requires_cuda


class InductorAnnotationTestCase(TestCase):
    def get_code(self):
        def f(a, b):
            return a + b, a * b

        a = torch.randn(5, device="cuda")
        b = torch.randn(5, device="cuda")
        f_comp = torch.compile(f)

        _, code = run_and_get_code(f_comp, a, b)
        return code[0]

    @requires_cuda
    def test_no_annotations(self):
        code = self.get_code()

        self.assertTrue("from torch.cuda import nvtx" not in code)
        self.assertTrue("training_annotation" not in code)

    @inductor_config.patch(annotate_training=True)
    @requires_cuda
    def test_training_annotation(self):
        code = self.get_code()

        self.assertTrue("from torch.cuda import nvtx" in code)
        self.assertEqual(
            code.count("training_annotation = nvtx._device_range_start('inference')"), 1
        )
        self.assertEqual(code.count("nvtx._device_range_end(training_annotation)"), 1)


if __name__ == "__main__":
    run_tests()