tritonparse 0.2.4.dev20251014071550__py3-none-any.whl → 0.3.1.dev20251015071527__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.

@@ -40,6 +40,7 @@ def _add_reproducer_args(parser: argparse.ArgumentParser) -> None:
40
40
  "Kernel import strategy:\n"
41
41
  " default: Import kernel from original file (current behavior)\n"
42
42
  " copy: Embed kernel source code directly in reproducer\n"
43
+ " override-ttir: Use TTIR from compilation event (bypass Python frontend)\n"
43
44
  "Defaults to 'default'."
44
45
  ),
45
46
  )
@@ -46,6 +46,15 @@ def reproduce(
46
46
  out_dir, context_bundle.kernel_info.function_name
47
47
  )
48
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
+
49
58
  logger.debug("Loading reproducer template.")
50
59
  template_code = load_template_code(template)
51
60
 
@@ -58,6 +67,7 @@ def reproduce(
58
67
  context_bundle,
59
68
  temp_json_path=temp_json_path,
60
69
  kernel_import=kernel_import,
70
+ comp_json_filename=comp_json_path.name if comp_json_path else None,
61
71
  )
62
72
 
63
73
  out_py_path.write_text(final_code, encoding="utf-8")
@@ -77,6 +77,9 @@ class DefaultPlaceholderReplacer(PlaceholderReplacer):
77
77
  super().__init__()
78
78
  # Register all default handlers
79
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
+ )
80
83
  self.register("# {{KERNEL_SYSPATH_PLACEHOLDER}}", self._replace_kernel_syspath)
81
84
  self.register("# {{KERNEL_IMPORT_PLACEHOLDER}}", self._replace_kernel_import)
82
85
  self.register(
@@ -92,6 +95,65 @@ class DefaultPlaceholderReplacer(PlaceholderReplacer):
92
95
  raise ValueError("temp_json_path is required for JSON filename replacement")
93
96
  return code.replace("{{JSON_FILE_NAME_PLACEHOLDER}}", temp_json_path.name)
94
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
+
95
157
  def _replace_kernel_syspath(
96
158
  self, code: str, context_bundle: ContextBundle, **kwargs
97
159
  ) -> str:
@@ -106,6 +168,9 @@ class DefaultPlaceholderReplacer(PlaceholderReplacer):
106
168
  "# Kernel sys.path setup skipped - kernel source code embedded below"
107
169
  )
108
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)
109
174
  else:
110
175
  raise ValueError(f"Unknown kernel_import mode: {kernel_import}")
111
176
 
@@ -146,6 +211,9 @@ class DefaultPlaceholderReplacer(PlaceholderReplacer):
146
211
  embedded_code += f"\n\n# Use kernel function directly\nimported_kernel_function = {func_name}"
147
212
 
148
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)
149
217
  else:
150
218
  raise ValueError(f"Unknown kernel_import mode: {kernel_import}")
151
219
 
@@ -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}}
@@ -6,10 +6,13 @@ class KernelImportMode(str, Enum):
6
6
  Kernel import strategy for reproducer generation.
7
7
 
8
8
  Inherits from str to allow direct string comparison and use in argparse.
9
- """
10
9
 
11
- DEFAULT = "default" # Import kernel from original file (current behavior)
12
- COPY = "copy" # Embed kernel source code directly in reproducer
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
+ """
13
15
 
14
- # Future modes can be added here:
15
- # OVERRIDE_TTIR = "override-ttir" # Use TTIR from compilation event with monkeypatch
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.2.4.dev20251014071550
3
+ Version: 0.3.1.dev20251015071527
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
@@ -15,14 +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=xV3HZdNiWF44JCfJOGKHpoF8TErqbm4ohuLAK0pXcRw,1432
19
- tritonparse/reproducer/orchestrator.py,sha256=AtfR78HAsqDYMF-C00-jH6jVWs3aQ0bt74RBCakoqyc,2767
20
- tritonparse/reproducer/placeholder_replacer.py,sha256=0dtnfuaVqj_aX2fH4omMPFeIz6673Vc4yeQcZCLr5UA,6425
21
- tritonparse/reproducer/types.py,sha256=3cwVzWe4wRJXtR_KCta8hYtIwNQOxL5SJDocLnMQNgg,485
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
22
22
  tritonparse/reproducer/utils.py,sha256=UTclw48vH49g6Z2ljJL5DOZ6Rl4UDudyr0PeUySa3p8,13857
23
23
  tritonparse/reproducer/ingestion/ndjson.py,sha256=pEujTl5xXW2E2DEW8ngxXQ8qP9oawb90wBVTWHDs1jk,7372
24
24
  tritonparse/reproducer/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- tritonparse/reproducer/templates/example.py,sha256=gOYKKKptvzyI4mq4eUygi1NrIEQkChm4d1bJXed1w5U,13904
25
+ tritonparse/reproducer/templates/example.py,sha256=QAyykFvmd1nI4ZvCjkJfrpAs2XBsMnFOK6WzhXxQ1uI,13963
26
26
  tritonparse/reproducer/templates/loader.py,sha256=HqjfThdDVg7q2bYWry78sIaVRkUpkcA8KQDt83YrlVE,1920
27
27
  tritonparse/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  tritonparse/tools/decompress_bin_ndjson.py,sha256=kpt7DM_sSA334F1X45xdkP2OR9LuB27Pc50EkGr6CPM,4144
@@ -31,9 +31,9 @@ tritonparse/tools/format_fix.py,sha256=Ol0Sjui8D7OzHwbamAfGnq8V5Y63uwNaFTKSORN5H
31
31
  tritonparse/tools/load_tensor.py,sha256=94-TiSYlpXJx4MPmGK1ovmZlTt56Q_B3KQeCPaA6Cnw,2734
32
32
  tritonparse/tools/prettify_ndjson.py,sha256=r2YlHwFDTHgML7KljRmMsHaDg29q8gOQAgyDKWJhxRM,11062
33
33
  tritonparse/tools/readme.md,sha256=w6PWYfYnRgoPArLjxG9rVrpcLUkoVMGuRlbpF-o0IQM,110
34
- tritonparse-0.2.4.dev20251014071550.dist-info/licenses/LICENSE,sha256=4ZciugpyN7wcM4L-9pyDh_etvMUeIfBhDTyH1zeZlQM,1515
35
- tritonparse-0.2.4.dev20251014071550.dist-info/METADATA,sha256=NRX3WAhjKHGcj7dw72sUFiiKzuAhiqgWDwRxaKvoXiM,8278
36
- tritonparse-0.2.4.dev20251014071550.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
- tritonparse-0.2.4.dev20251014071550.dist-info/entry_points.txt,sha256=wEXdaieDoRRCCdhEv2p_C68iytnaXU_2pwt5CqjfbWY,56
38
- tritonparse-0.2.4.dev20251014071550.dist-info/top_level.txt,sha256=ITcTKgp3vf_bXV9vixuQU9IrZa3L1EfDSZwvRzRaoJU,12
39
- tritonparse-0.2.4.dev20251014071550.dist-info/RECORD,,
34
+ tritonparse-0.3.1.dev20251015071527.dist-info/licenses/LICENSE,sha256=4ZciugpyN7wcM4L-9pyDh_etvMUeIfBhDTyH1zeZlQM,1515
35
+ tritonparse-0.3.1.dev20251015071527.dist-info/METADATA,sha256=CPxG95kX-c5EcK739gu_ky-k0TxDY1pAL9SaXOKBNDw,8278
36
+ tritonparse-0.3.1.dev20251015071527.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
37
+ tritonparse-0.3.1.dev20251015071527.dist-info/entry_points.txt,sha256=wEXdaieDoRRCCdhEv2p_C68iytnaXU_2pwt5CqjfbWY,56
38
+ tritonparse-0.3.1.dev20251015071527.dist-info/top_level.txt,sha256=ITcTKgp3vf_bXV9vixuQU9IrZa3L1EfDSZwvRzRaoJU,12
39
+ tritonparse-0.3.1.dev20251015071527.dist-info/RECORD,,