tritonparse 0.2.4.dev20251013071533__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of tritonparse might be problematic. Click here for more details.
- tritonparse/cli.py +1 -0
- tritonparse/reproducer/cli.py +15 -0
- tritonparse/reproducer/orchestrator.py +17 -1
- tritonparse/reproducer/placeholder_replacer.py +116 -4
- tritonparse/reproducer/templates/example.py +3 -0
- tritonparse/reproducer/types.py +18 -0
- {tritonparse-0.2.4.dev20251013071533.dist-info → tritonparse-0.3.0.dist-info}/METADATA +1 -1
- {tritonparse-0.2.4.dev20251013071533.dist-info → tritonparse-0.3.0.dist-info}/RECORD +12 -11
- {tritonparse-0.2.4.dev20251013071533.dist-info → tritonparse-0.3.0.dist-info}/WHEEL +0 -0
- {tritonparse-0.2.4.dev20251013071533.dist-info → tritonparse-0.3.0.dist-info}/entry_points.txt +0 -0
- {tritonparse-0.2.4.dev20251013071533.dist-info → tritonparse-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {tritonparse-0.2.4.dev20251013071533.dist-info → tritonparse-0.3.0.dist-info}/top_level.txt +0 -0
tritonparse/cli.py
CHANGED
tritonparse/reproducer/cli.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import argparse
|
|
2
2
|
|
|
3
|
+
from tritonparse.reproducer.types import KernelImportMode
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
def _add_reproducer_args(parser: argparse.ArgumentParser) -> None:
|
|
5
7
|
"""Add common arguments for the reproducer to a parser."""
|
|
@@ -29,3 +31,16 @@ def _add_reproducer_args(parser: argparse.ArgumentParser) -> None:
|
|
|
29
31
|
"Defaults to 'example'."
|
|
30
32
|
),
|
|
31
33
|
)
|
|
34
|
+
parser.add_argument(
|
|
35
|
+
"--kernel-import",
|
|
36
|
+
type=KernelImportMode,
|
|
37
|
+
choices=list(KernelImportMode),
|
|
38
|
+
default=KernelImportMode.DEFAULT,
|
|
39
|
+
help=(
|
|
40
|
+
"Kernel import strategy:\n"
|
|
41
|
+
" default: Import kernel from original file (current behavior)\n"
|
|
42
|
+
" copy: Embed kernel source code directly in reproducer\n"
|
|
43
|
+
" override-ttir: Use TTIR from compilation event (bypass Python frontend)\n"
|
|
44
|
+
"Defaults to 'default'."
|
|
45
|
+
),
|
|
46
|
+
)
|
|
@@ -7,6 +7,7 @@ from tritonparse.reproducer.placeholder_replacer import (
|
|
|
7
7
|
PlaceholderReplacer,
|
|
8
8
|
)
|
|
9
9
|
from tritonparse.reproducer.templates.loader import load_template_code
|
|
10
|
+
from tritonparse.reproducer.types import KernelImportMode
|
|
10
11
|
from tritonparse.reproducer.utils import determine_output_paths
|
|
11
12
|
|
|
12
13
|
from tritonparse.tools.prettify_ndjson import load_ndjson, save_prettified_json
|
|
@@ -19,6 +20,7 @@ def reproduce(
|
|
|
19
20
|
out_dir: str,
|
|
20
21
|
template: str,
|
|
21
22
|
replacer: Optional[PlaceholderReplacer] = None,
|
|
23
|
+
kernel_import: KernelImportMode = KernelImportMode.DEFAULT,
|
|
22
24
|
) -> dict[str, Path]:
|
|
23
25
|
"""
|
|
24
26
|
Generate a reproducer script from NDJSON trace file.
|
|
@@ -29,6 +31,7 @@ def reproduce(
|
|
|
29
31
|
out_dir: Output directory for reproducer files.
|
|
30
32
|
template: Template name to use for the reproducer.
|
|
31
33
|
replacer: Optional custom PlaceholderReplacer instance. If None, uses DefaultPlaceholderReplacer.
|
|
34
|
+
kernel_import: Kernel import mode (DEFAULT or COPY).
|
|
32
35
|
"""
|
|
33
36
|
logger.debug(f"Building bundle from {input_path} at line {line_index}")
|
|
34
37
|
events = load_ndjson(Path(input_path))
|
|
@@ -43,6 +46,15 @@ def reproduce(
|
|
|
43
46
|
out_dir, context_bundle.kernel_info.function_name
|
|
44
47
|
)
|
|
45
48
|
save_prettified_json(context_bundle.raw_launch_event, temp_json_path)
|
|
49
|
+
|
|
50
|
+
# Save compilation event JSON if using OVERRIDE_TTIR mode
|
|
51
|
+
comp_json_path = None
|
|
52
|
+
if kernel_import == KernelImportMode.OVERRIDE_TTIR:
|
|
53
|
+
comp_json_path = (
|
|
54
|
+
temp_json_path.parent / f"{temp_json_path.stem}_compilation.json"
|
|
55
|
+
)
|
|
56
|
+
save_prettified_json(context_bundle.raw_comp_event, comp_json_path)
|
|
57
|
+
|
|
46
58
|
logger.debug("Loading reproducer template.")
|
|
47
59
|
template_code = load_template_code(template)
|
|
48
60
|
|
|
@@ -51,7 +63,11 @@ def reproduce(
|
|
|
51
63
|
if replacer is None:
|
|
52
64
|
replacer = DefaultPlaceholderReplacer()
|
|
53
65
|
final_code = replacer.replace(
|
|
54
|
-
template_code,
|
|
66
|
+
template_code,
|
|
67
|
+
context_bundle,
|
|
68
|
+
temp_json_path=temp_json_path,
|
|
69
|
+
kernel_import=kernel_import,
|
|
70
|
+
comp_json_filename=comp_json_path.name if comp_json_path else None,
|
|
55
71
|
)
|
|
56
72
|
|
|
57
73
|
out_py_path.write_text(final_code, encoding="utf-8")
|
|
@@ -3,6 +3,7 @@ from abc import ABC
|
|
|
3
3
|
from typing import Any, Dict, Protocol
|
|
4
4
|
|
|
5
5
|
from tritonparse.reproducer.ingestion.ndjson import ContextBundle
|
|
6
|
+
from tritonparse.reproducer.types import KernelImportMode
|
|
6
7
|
from tritonparse.reproducer.utils import (
|
|
7
8
|
_generate_import_statements,
|
|
8
9
|
_generate_invocation_snippet,
|
|
@@ -76,6 +77,9 @@ class DefaultPlaceholderReplacer(PlaceholderReplacer):
|
|
|
76
77
|
super().__init__()
|
|
77
78
|
# Register all default handlers
|
|
78
79
|
self.register("{{JSON_FILE_NAME_PLACEHOLDER}}", self._replace_json_filename)
|
|
80
|
+
self.register(
|
|
81
|
+
"# {{IR_OVERRIDE_SETUP_PLACEHOLDER}}", self._replace_ir_override_setup
|
|
82
|
+
)
|
|
79
83
|
self.register("# {{KERNEL_SYSPATH_PLACEHOLDER}}", self._replace_kernel_syspath)
|
|
80
84
|
self.register("# {{KERNEL_IMPORT_PLACEHOLDER}}", self._replace_kernel_import)
|
|
81
85
|
self.register(
|
|
@@ -91,19 +95,127 @@ class DefaultPlaceholderReplacer(PlaceholderReplacer):
|
|
|
91
95
|
raise ValueError("temp_json_path is required for JSON filename replacement")
|
|
92
96
|
return code.replace("{{JSON_FILE_NAME_PLACEHOLDER}}", temp_json_path.name)
|
|
93
97
|
|
|
98
|
+
def _replace_ir_override_setup(
|
|
99
|
+
self, code: str, context_bundle: ContextBundle, **kwargs
|
|
100
|
+
) -> str:
|
|
101
|
+
"""Replace the IR override setup placeholder."""
|
|
102
|
+
kernel_import = kwargs.get("kernel_import", KernelImportMode.DEFAULT)
|
|
103
|
+
|
|
104
|
+
if kernel_import != KernelImportMode.OVERRIDE_TTIR:
|
|
105
|
+
return code.replace("# {{IR_OVERRIDE_SETUP_PLACEHOLDER}}", "")
|
|
106
|
+
|
|
107
|
+
comp_json_filename = kwargs.get("comp_json_filename")
|
|
108
|
+
if not comp_json_filename:
|
|
109
|
+
raise ValueError("comp_json_filename is required for OVERRIDE_TTIR mode")
|
|
110
|
+
|
|
111
|
+
setup_code = f'''
|
|
112
|
+
def create_ttir_tempfile():
|
|
113
|
+
"""Extract TTIR from compilation event and create temporary file."""
|
|
114
|
+
script_dir = Path(__file__).resolve().parent
|
|
115
|
+
comp_json_file = script_dir / "{comp_json_filename}"
|
|
116
|
+
|
|
117
|
+
with open(comp_json_file, 'r') as f:
|
|
118
|
+
comp_data = json.load(f)
|
|
119
|
+
|
|
120
|
+
# Extract TTIR content
|
|
121
|
+
kernel_name = comp_data['payload']['metadata']['name']
|
|
122
|
+
ttir_key = f"{{kernel_name}}.ttir"
|
|
123
|
+
ttir_content = comp_data['payload']['file_content'][ttir_key]
|
|
124
|
+
|
|
125
|
+
# Create temporary file
|
|
126
|
+
temp_file = tempfile.NamedTemporaryFile(
|
|
127
|
+
mode='w',
|
|
128
|
+
suffix='.ttir',
|
|
129
|
+
delete=False,
|
|
130
|
+
prefix=f'{{kernel_name}}_'
|
|
131
|
+
)
|
|
132
|
+
temp_file.write(ttir_content)
|
|
133
|
+
temp_file.close()
|
|
134
|
+
return temp_file.name
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# Monkeypatch triton.autotune to use our TTIR
|
|
138
|
+
_ttir_file = create_ttir_tempfile()
|
|
139
|
+
_original_autotune = None
|
|
140
|
+
|
|
141
|
+
def _patched_autotune(configs, key=None, **kwargs):
|
|
142
|
+
"""Patched autotune that uses our TTIR file."""
|
|
143
|
+
import triton
|
|
144
|
+
# Replace configs with our single config using ir_override
|
|
145
|
+
new_configs = [triton.Config(kwargs={{}}, ir_override=_ttir_file)]
|
|
146
|
+
# Call original autotune with our config
|
|
147
|
+
return _original_autotune(new_configs, key=[], **kwargs)
|
|
148
|
+
|
|
149
|
+
# Apply the monkeypatch before importing the kernel
|
|
150
|
+
import triton
|
|
151
|
+
_original_autotune = triton.autotune
|
|
152
|
+
triton.autotune = _patched_autotune
|
|
153
|
+
'''
|
|
154
|
+
|
|
155
|
+
return code.replace("# {{IR_OVERRIDE_SETUP_PLACEHOLDER}}", setup_code)
|
|
156
|
+
|
|
94
157
|
def _replace_kernel_syspath(
|
|
95
158
|
self, code: str, context_bundle: ContextBundle, **kwargs
|
|
96
159
|
) -> str:
|
|
97
160
|
"""Replace the kernel sys.path placeholder."""
|
|
98
|
-
|
|
99
|
-
|
|
161
|
+
kernel_import = kwargs.get("kernel_import", KernelImportMode.DEFAULT)
|
|
162
|
+
|
|
163
|
+
if kernel_import == KernelImportMode.DEFAULT:
|
|
164
|
+
sys_stmt, _ = _generate_import_statements(context_bundle.kernel_info)
|
|
165
|
+
return code.replace("# {{KERNEL_SYSPATH_PLACEHOLDER}}", sys_stmt)
|
|
166
|
+
elif kernel_import == KernelImportMode.COPY:
|
|
167
|
+
comment = (
|
|
168
|
+
"# Kernel sys.path setup skipped - kernel source code embedded below"
|
|
169
|
+
)
|
|
170
|
+
return code.replace("# {{KERNEL_SYSPATH_PLACEHOLDER}}", comment)
|
|
171
|
+
elif kernel_import == KernelImportMode.OVERRIDE_TTIR:
|
|
172
|
+
comment = "# Kernel sys.path setup skipped - using IR override mode"
|
|
173
|
+
return code.replace("# {{KERNEL_SYSPATH_PLACEHOLDER}}", comment)
|
|
174
|
+
else:
|
|
175
|
+
raise ValueError(f"Unknown kernel_import mode: {kernel_import}")
|
|
100
176
|
|
|
101
177
|
def _replace_kernel_import(
|
|
102
178
|
self, code: str, context_bundle: ContextBundle, **kwargs
|
|
103
179
|
) -> str:
|
|
104
180
|
"""Replace the kernel import placeholder."""
|
|
105
|
-
|
|
106
|
-
|
|
181
|
+
kernel_import = kwargs.get("kernel_import", KernelImportMode.DEFAULT)
|
|
182
|
+
|
|
183
|
+
if kernel_import == KernelImportMode.DEFAULT:
|
|
184
|
+
_, import_statement = _generate_import_statements(
|
|
185
|
+
context_bundle.kernel_info
|
|
186
|
+
)
|
|
187
|
+
return code.replace("# {{KERNEL_IMPORT_PLACEHOLDER}}", import_statement)
|
|
188
|
+
elif kernel_import == KernelImportMode.COPY:
|
|
189
|
+
source_code = context_bundle.kernel_info.source_code
|
|
190
|
+
func_name = context_bundle.kernel_info.function_name
|
|
191
|
+
|
|
192
|
+
if not source_code or not source_code.strip():
|
|
193
|
+
raise ValueError("Kernel source code is empty, cannot use 'copy' mode")
|
|
194
|
+
if not func_name:
|
|
195
|
+
raise ValueError(
|
|
196
|
+
"Cannot determine kernel function name for 'copy' mode"
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
# Add common imports needed for most Triton kernels
|
|
200
|
+
import_lines = [
|
|
201
|
+
"import torch",
|
|
202
|
+
"import numpy as np",
|
|
203
|
+
"import triton",
|
|
204
|
+
"import triton.language as tl",
|
|
205
|
+
"",
|
|
206
|
+
]
|
|
207
|
+
|
|
208
|
+
# Combine: imports + kernel source code + alias
|
|
209
|
+
embedded_code = "\n".join(import_lines)
|
|
210
|
+
embedded_code += "\n" + source_code
|
|
211
|
+
embedded_code += f"\n\n# Use kernel function directly\nimported_kernel_function = {func_name}"
|
|
212
|
+
|
|
213
|
+
return code.replace("# {{KERNEL_IMPORT_PLACEHOLDER}}", embedded_code)
|
|
214
|
+
elif kernel_import == KernelImportMode.OVERRIDE_TTIR:
|
|
215
|
+
comment = "# Kernel import skipped - using IR override mode with TTIR"
|
|
216
|
+
return code.replace("# {{KERNEL_IMPORT_PLACEHOLDER}}", comment)
|
|
217
|
+
else:
|
|
218
|
+
raise ValueError(f"Unknown kernel_import mode: {kernel_import}")
|
|
107
219
|
|
|
108
220
|
def _replace_kernel_invocation(
|
|
109
221
|
self, code: str, context_bundle: ContextBundle, **kwargs
|
|
@@ -6,6 +6,7 @@ It contains a smallest testing example for a Triton kernel.
|
|
|
6
6
|
import gzip
|
|
7
7
|
import hashlib
|
|
8
8
|
import importlib
|
|
9
|
+
import importlib.util
|
|
9
10
|
import io
|
|
10
11
|
import json
|
|
11
12
|
import logging
|
|
@@ -16,6 +17,8 @@ from typing import Union
|
|
|
16
17
|
|
|
17
18
|
import torch
|
|
18
19
|
|
|
20
|
+
# {{IR_OVERRIDE_SETUP_PLACEHOLDER}}
|
|
21
|
+
|
|
19
22
|
# {{KERNEL_SYSPATH_PLACEHOLDER}}
|
|
20
23
|
|
|
21
24
|
# {{KERNEL_IMPORT_PLACEHOLDER}}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class KernelImportMode(str, Enum):
|
|
5
|
+
"""
|
|
6
|
+
Kernel import strategy for reproducer generation.
|
|
7
|
+
|
|
8
|
+
Inherits from str to allow direct string comparison and use in argparse.
|
|
9
|
+
|
|
10
|
+
Attributes:
|
|
11
|
+
DEFAULT: Import kernel from original file (current behavior).
|
|
12
|
+
COPY: Embed kernel source code directly in reproducer.
|
|
13
|
+
OVERRIDE_TTIR: Use TTIR from compilation event with monkeypatch.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
DEFAULT = "default"
|
|
17
|
+
COPY = "copy"
|
|
18
|
+
OVERRIDE_TTIR = "override-ttir"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tritonparse
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: TritonParse: A Compiler Tracer, Visualizer, and mini-Reproducer Generator for Triton Kernels
|
|
5
5
|
Author-email: Yueming Hao <yhao@meta.com>
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
tritonparse/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
tritonparse/__main__.py,sha256=wu5N2wk8mvBgyvr2ghmQf4prezAe0_i-p123VVreyYc,62
|
|
3
|
-
tritonparse/cli.py,sha256=
|
|
3
|
+
tritonparse/cli.py,sha256=w_sCIv1NlcGDzoflsYuTvtQis92_YuZEC51ZlTVsYCU,2517
|
|
4
4
|
tritonparse/common.py,sha256=9coQbzpyHWAAdv6lx2YQTualiIH49ULJuZTA7VB_V7A,13946
|
|
5
5
|
tritonparse/context_manager.py,sha256=MqAWI8uD1uCeCbmkcEWPejc5_IeY---BdajhsSR9T_E,2221
|
|
6
6
|
tritonparse/event_diff.py,sha256=yOD6uNxLJroatfx2nEGr-erw24ObOrHU9P6V5pzr8do,4907
|
|
@@ -15,13 +15,14 @@ tritonparse/tp_logger.py,sha256=vXzY7hMDmVnRBGBhIjFZe3nHZzG5NKKPONGUszJhGgU,242
|
|
|
15
15
|
tritonparse/trace_processor.py,sha256=brQBt26jdB6-quJXP5-warp2j31JSjOOFJa5ayiUZ5k,12963
|
|
16
16
|
tritonparse/utils.py,sha256=Jnlptcd79llSDev-_1XyyOnv2izUqv0PEL74A8GF2tc,4565
|
|
17
17
|
tritonparse/reproducer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
-
tritonparse/reproducer/cli.py,sha256=
|
|
19
|
-
tritonparse/reproducer/orchestrator.py,sha256=
|
|
20
|
-
tritonparse/reproducer/placeholder_replacer.py,sha256=
|
|
18
|
+
tritonparse/reproducer/cli.py,sha256=MqYuuAP-uAIWWLQxixwyyBHJGSaQdG3xXGaVjERTLX8,1522
|
|
19
|
+
tritonparse/reproducer/orchestrator.py,sha256=rZyA7TNVNgVuQkLlte3sPi1tQZ0ZAXGiFd5IJRyaD9Q,3180
|
|
20
|
+
tritonparse/reproducer/placeholder_replacer.py,sha256=YPspknFkoZ1WLHQBrJefSlp4RerbdX9LpBe-QSCmMRs,9026
|
|
21
|
+
tritonparse/reproducer/types.py,sha256=AfVl83zoJZQ58JJoplCcMC51gK-M-OKcafatYEIGgW0,509
|
|
21
22
|
tritonparse/reproducer/utils.py,sha256=UTclw48vH49g6Z2ljJL5DOZ6Rl4UDudyr0PeUySa3p8,13857
|
|
22
23
|
tritonparse/reproducer/ingestion/ndjson.py,sha256=pEujTl5xXW2E2DEW8ngxXQ8qP9oawb90wBVTWHDs1jk,7372
|
|
23
24
|
tritonparse/reproducer/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
-
tritonparse/reproducer/templates/example.py,sha256=
|
|
25
|
+
tritonparse/reproducer/templates/example.py,sha256=QAyykFvmd1nI4ZvCjkJfrpAs2XBsMnFOK6WzhXxQ1uI,13963
|
|
25
26
|
tritonparse/reproducer/templates/loader.py,sha256=HqjfThdDVg7q2bYWry78sIaVRkUpkcA8KQDt83YrlVE,1920
|
|
26
27
|
tritonparse/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
27
28
|
tritonparse/tools/decompress_bin_ndjson.py,sha256=kpt7DM_sSA334F1X45xdkP2OR9LuB27Pc50EkGr6CPM,4144
|
|
@@ -30,9 +31,9 @@ tritonparse/tools/format_fix.py,sha256=Ol0Sjui8D7OzHwbamAfGnq8V5Y63uwNaFTKSORN5H
|
|
|
30
31
|
tritonparse/tools/load_tensor.py,sha256=94-TiSYlpXJx4MPmGK1ovmZlTt56Q_B3KQeCPaA6Cnw,2734
|
|
31
32
|
tritonparse/tools/prettify_ndjson.py,sha256=r2YlHwFDTHgML7KljRmMsHaDg29q8gOQAgyDKWJhxRM,11062
|
|
32
33
|
tritonparse/tools/readme.md,sha256=w6PWYfYnRgoPArLjxG9rVrpcLUkoVMGuRlbpF-o0IQM,110
|
|
33
|
-
tritonparse-0.
|
|
34
|
-
tritonparse-0.
|
|
35
|
-
tritonparse-0.
|
|
36
|
-
tritonparse-0.
|
|
37
|
-
tritonparse-0.
|
|
38
|
-
tritonparse-0.
|
|
34
|
+
tritonparse-0.3.0.dist-info/licenses/LICENSE,sha256=4ZciugpyN7wcM4L-9pyDh_etvMUeIfBhDTyH1zeZlQM,1515
|
|
35
|
+
tritonparse-0.3.0.dist-info/METADATA,sha256=YoDJfNP6fBgH4ypV7Fvzmy-en3Ax5mIuM660u6S3gnc,8260
|
|
36
|
+
tritonparse-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
37
|
+
tritonparse-0.3.0.dist-info/entry_points.txt,sha256=wEXdaieDoRRCCdhEv2p_C68iytnaXU_2pwt5CqjfbWY,56
|
|
38
|
+
tritonparse-0.3.0.dist-info/top_level.txt,sha256=ITcTKgp3vf_bXV9vixuQU9IrZa3L1EfDSZwvRzRaoJU,12
|
|
39
|
+
tritonparse-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
{tritonparse-0.2.4.dev20251013071533.dist-info → tritonparse-0.3.0.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{tritonparse-0.2.4.dev20251013071533.dist-info → tritonparse-0.3.0.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|