{
"name": "BackendCompilerFailed",
"message": "backend='inductor' raised:
ImportError: cannot import name 'triton_key' from 'triton.compiler.compiler' (/home/developer6/.local/lib/python3.10/site-packages/triton/compiler/compiler.py)
Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information
",
"stack": "---------------------------------------------------------------------------
BackendCompilerFailed Traceback (most recent call last)
Cell In[1], line 3
1 from fam.llm.ckpt_inference import TTS
----> 3 model = TTS(ckpt_path='/home/developer6/.cache/huggingface/hub/models--kotoba-speech--azure-8node-3cbooks_bpe_mls_resumed_bjkmcu1e/snapshots/17f3f0a85d3380169988382b1fba69e279d5e05f/epoch=8-step=1099726.ckpt')
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_dynamo/output_graph.py:1123, in OutputGraph.compile_subgraph(self, tx, partial_convert, reason)
1120 output = []
1121 if count_calls(self.graph) != 0 or len(pass2.graph_outputs) != 0:
1122 output.extend(
-> 1123 self.compile_and_call_fx_graph(tx, pass2.graph_output_vars(), root)
1124 )
1126 if len(pass2.graph_outputs) != 0:
1127 output.append(pass2.create_store(graph_output_var))
File ~/anaconda3/envs/py310/lib/python3.10/contextlib.py:79, in ContextDecorator.call..inner(*args, **kwds)
76 @wraps(func)
77 def inner(*args, **kwds):
78 with self._recreate_cm():
---> 79 return func(*args, **kwds)
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_dynamo/output_graph.py:1318, in OutputGraph.compile_and_call_fx_graph(self, tx, rv, root)
1315 self.tracing_context.fake_mode = backend_fake_mode
1317 with self.restore_global_state():
-> 1318 compiled_fn = self.call_user_compiler(gm)
1320 from torch.fx._lazy_graph_module import _LazyGraphModule
1322 if isinstance(compiled_fn, _LazyGraphModule) or (
1323 isinstance(getattr(compiled_fn, "self", None), _LazyGraphModule)
1324 and compiled_fn.name == "_lazy_forward"
(...)
1328 # this is a _LazyGraphModule. This makes it easier for dynamo to
1329 # optimize a _LazyGraphModule.
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_dynamo/utils.py:230, in dynamo_timed..dynamo_timed_inner..time_wrapper(*args, **kwargs)
228 with torch.profiler.record_function(f"{key} (dynamo_timed)"):
229 t0 = time.time()
--> 230 r = func(*args, **kwargs)
231 time_spent = time.time() - t0
232 compilation_time_metrics[key].append(time_spent)
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_dynamo/output_graph.py:1409, in OutputGraph.call_user_compiler(self, gm)
1407 raise e
1408 except Exception as e:
-> 1409 raise BackendCompilerFailed(self.compiler_fn, e).with_traceback(
1410 e.traceback
1411 ) from None
1413 signpost_event(
1414 "dynamo",
1415 "OutputGraph.call_user_compiler",
(...)
1421 },
1422 )
1424 return compiled_fn
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_dynamo/output_graph.py:1390, in OutputGraph.call_user_compiler(self, gm)
1388 if config.verify_correctness:
1389 compiler_fn = WrapperBackend(compiler_fn)
-> 1390 compiled_fn = compiler_fn(gm, self.example_inputs())
1391 _step_logger()(logging.INFO, f"done compiler function {name}")
1392 assert callable(compiled_fn), "compiler_fn did not return callable"
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_functorch/aot_autograd.py:953, in aot_module_simplified(mod, args, fw_compiler, bw_compiler, partition_fn, decompositions, keep_inference_input_mutations, inference_compiler)
937 aot_config = AOTConfig(
938 fw_compiler=fw_compiler,
939 bw_compiler=bw_compiler,
(...)
949 no_tangents=False,
950 )
952 with compiled_autograd.disable():
--> 953 compiled_fn, _ = create_aot_dispatcher_function(
954 functional_call,
955 full_args,
956 aot_config,
957 )
959 if isinstance(mod, torch._dynamo.utils.GmWrapper):
960 # This function is called by the flatten_graph_inputs wrapper, which boxes
961 # the inputs so that they can be freed before the end of this scope.
962 # For overhead reasons, this is not the default wrapper, see comment:
963 # https://github.com/pytorch/pytorch/pull/122535/files#r1560096481
964 def boxed_forward(runtime_args: List[Any]):
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_dynamo/utils.py:230, in dynamo_timed..dynamo_timed_inner..time_wrapper(*args, **kwargs)
228 with torch.profiler.record_function(f"{key} (dynamo_timed)"):
229 t0 = time.time()
--> 230 r = func(*args, **kwargs)
231 time_spent = time.time() - t0
232 compilation_time_metrics[key].append(time_spent)
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_functorch/_aot_autograd/jit_compile_runtime_wrappers.py:168, in aot_dispatch_base(flat_fn, flat_args, aot_config, fw_metadata)
161 tracing_context.fw_metadata = (
162 fw_metadata
163 if maybe_subclass_meta is None
164 else maybe_subclass_meta.fw_metadata
165 )
167 with TracingContext.report_output_strides() as fwd_output_strides:
--> 168 compiled_fw = compiler(fw_module, updated_flat_args)
170 if fakified_out_wrapper.needs_post_compile:
171 fakified_out_wrapper.set_fwd_output_strides(fwd_output_strides)
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_dynamo/utils.py:230, in dynamo_timed..dynamo_timed_inner..time_wrapper(*args, **kwargs)
228 with torch.profiler.record_function(f"{key} (dynamo_timed)"):
229 t0 = time.time()
--> 230 r = func(*args, **kwargs)
231 time_spent = time.time() - t0
232 compilation_time_metrics[key].append(time_spent)
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_inductor/compile_fx.py:1409, in compile_fx..fw_compiler_base(model, example_inputs, is_inference)
1401 assert orig_output_end_idx <= num_model_outputs
1403 user_visible_outputs = dict.fromkeys(
1404 n.name
1405 for n in model_outputs[original_output_start_index:orig_output_end_idx]
1406 if isinstance(n, torch.fx.Node)
1407 )
-> 1409 return inner_compile(
1410 model,
1411 example_inputs,
1412 static_input_idxs=get_static_input_idxs(fixed),
1413 cudagraphs=cudagraphs,
1414 graph_id=graph_id,
1415 is_inference=is_inference,
1416 boxed_forward_device_index=forward_device,
1417 user_visible_outputs=user_visible_outputs,
1418 )
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_dynamo/repro/after_aot.py:84, in wrap_compiler_debug..debug_wrapper(gm, example_inputs, **kwargs)
79 assert config.repro_after in ("dynamo", "aot", None)
81 try:
82 # Call the compiler_fn - which is either aot_autograd or inductor
83 # with fake inputs
---> 84 inner_compiled_fn = compiler_fn(gm, example_inputs)
85 except Exception as e:
86 # TODO: Failures here are troublesome because no real inputs,
87 # need a different serialization strategy
88 if config.repro_after == "aot":
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_inductor/debug.py:304, in DebugContext.wrap..inner(*args, **kwargs)
301 @functools.wraps(fn)
302 def inner(*args, **kwargs):
303 with DebugContext():
--> 304 return fn(*args, **kwargs)
File ~/anaconda3/envs/py310/lib/python3.10/contextlib.py:79, in ContextDecorator.call..inner(*args, **kwds)
76 @wraps(func)
77 def inner(*args, **kwds):
78 with self._recreate_cm():
---> 79 return func(*args, **kwds)
File ~/anaconda3/envs/py310/lib/python3.10/contextlib.py:79, in ContextDecorator.call..inner(*args, **kwds)
76 @wraps(func)
77 def inner(*args, **kwds):
78 with self._recreate_cm():
---> 79 return func(*args, **kwds)
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_dynamo/utils.py:230, in dynamo_timed..dynamo_timed_inner..time_wrapper(*args, **kwargs)
228 with torch.profiler.record_function(f"{key} (dynamo_timed)"):
229 t0 = time.time()
--> 230 r = func(*args, **kwargs)
231 time_spent = time.time() - t0
232 compilation_time_metrics[key].append(time_spent)
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_inductor/codecache.py:702, in compiled_fx_graph_hash(gm, example_inputs, fx_kwargs, inputs_to_check)
693 def compiled_fx_graph_hash(
694 gm: torch.fx.GraphModule,
695 example_inputs: List[torch.Tensor],
696 fx_kwargs: Dict[str, Any],
697 inputs_to_check: Sequence[int],
698 ) -> str:
699 """
700 Generate a unique hash of the FX graph for caching.
701 """
--> 702 details = FxGraphHashDetails(gm, example_inputs, fx_kwargs, inputs_to_check)
703 # The prefix distinguishes among the other kinds of objects we
704 # cache in this module.
705 key = "f" + FxGraphCachePickler.get_hash(details)
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_inductor/codecache.py:681, in FxGraphHashDetails.init(self, gm, example_inputs, fx_kwargs, inputs_to_check)
679 # Also hash on various system info (including the triton compiler version).
680 self.torch_version = torch_key()
--> 681 self.system_info = CacheBase.get_system()
682 self.inductor_config = config.save_config_portable()
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_inductor/codecache.py:143, in CacheBase.get_system()
139 @staticmethod
140 @functools.lru_cache(None)
141 def get_system() -> Dict[str, Any]:
142 try:
--> 143 from triton.compiler.compiler import triton_key
145 # Use triton_key instead of triton.version as the version
146 # is not updated with each code change
147 triton_version = triton_key()
BackendCompilerFailed: backend='inductor' raised:
ImportError: cannot import name 'triton_key' from 'triton.compiler.compiler' (/home/developer6/.local/lib/python3.10/site-packages/triton/compiler/compiler.py)
Set TORCH_LOGS="+dynamo" and TORCHDYNAMO_VERBOSE=1 for more information
"
}
Error Overview:
You're encountering an error related to the inductor backend while attempting to import triton_key from triton.compiler.compiler. The traceback indicates that this ImportError is causing the BackendCompilerFailed exception.
Potential Causes:
Incorrect Triton Version: The version of the Triton library you're using might not include the triton_key or there could be a naming or structural change in the library.
Environment Issues: There might be conflicts or misconfigurations in your Python environment, such as multiple versions of Triton or improper installations.
Code Issues: If your code or dependencies specify certain versions that do not align with each other, it can lead to such errors.
Steps to Resolve:
1. Check Triton Installation:
Ensure that the Triton library is correctly installed and up-to-date.
sh
pip show triton
Ensure that the version displayed is expected and compatible. Also, make sure the triton and torch libraries are up-to-date:
sh
pip install --upgrade triton torch
2. Verify Triton Path:
Check that the triton module path is correct and consistent with your environment.
python
import triton
print(triton.__file__)
This will help you verify if the triton module being used is correct.
3. Explore Libray Internals:
Since the necessary import is from triton.compiler.compiler, check if triton_key or similar attributes are indeed present. Sometimes library internals change.
python
import triton.compiler.compiler as triton_compiler
print(dir(triton_compiler))
This will list all the attributes and methods inside the triton.compiler.compiler module. Look for anything that might be a typo or similarly named.
4. Version Compatibility:
Make sure that the version of Triton you are using is compatible with the version of PyTorch. Look up the dependencies in the documentation of the libraries or the project's requirements.txt file.
5. Environment Consistency:
Ensure your environment is using consistent versions. Often in complex environments or after multiple installations, inconsistencies can arise.
sh
conda list | grep triton
conda list | grep torch
Validate the versions listed and ensure they match the requirements for your project.
6. Temporary Workaround:
While the root cause is being resolved, if Triton is not a strict requirement, you can temporarily disable or bypass the parts of your code that depend on it and seek alternative implementations if possible.
Example:
In the specific sections of your code producing the error, wrap the imports in try-except blocks to handle scenarios where triton_key isn't available:
python
try:
from triton.compiler.compiler import triton_key
except ImportError:
triton_key = None
# Handle absence or define alternative logic
7. Reinstall Libraries:
Sometimes, a reinstallation of the libraries can solve hidden issues:
Look for documentation, changelogs, and community forums for insights on similar issues and troubleshooting advice. Patches or updates might already be available.
Conclusion:
Begin with ensuring that the Triton library and its dependencies are correctly installed and compatible with your PyTorch setup. Additionally, examining the internal structure of the Triton library can help identify if the triton_key has been moved or renamed. If issues persist, reinstallation, checking environment settings, and consulting documentation can aid in resolving the problem.
Thank you for providing the requirements.txt file. Based on the provided list, there are no explicit references to triton or torch, which might cause the PyTorch dependencies to be resolved to versions that are incompatible with triton.
To resolve possible version conflicts and ensure compatibility, let's add specific versions for PyTorch and Triton. Below are steps you can follow:
Steps to Ensure Compatibility:
Determine compatible versions:
Find versions of PyTorch and Triton that are known to work together. As of now, you can refer to PyTorch's compatibility list:
Add specific versions to requirements.txt:
You should specify the versions of PyTorch and Triton directly in your requirements.txt. For example, if using torch==2.0.1 and triton==2.0.0 is compatible:
Replace the torch and triton versions with the actual versions that are compatible based on the PyTorch documentation or compatibility matrix.
Conclusion:
Updating your requirements.txt to include explicit versions for torch and triton can help resolve version conflicts and ensure compatibility. Making sure your environment is clean and dependencies are correctly resolved will minimize such issues.
File ~/kotoba-voice/fam/llm/fast_inference_utils.py:50
48 torch._inductor.config.coordinate_descent_tuning = True
49 torch._inductor.config.triton.unique_kernel_names = True
---> 50 torch._inductor.config.fx_graph_cache = (
51 True # Experimental feature to reduce compilation times, will be on by default in future
52 )
54 # imports need to happen after setting above flags
55 from fam.llm.fast_model import Transformer
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/torch/_dynamo/config_utils.py:72, in ConfigModule.setattr(self, name, value)
70 super().setattr(name, value)
71 elif name not in self._allowed_keys:
---> 72 raise AttributeError(f"{self.name}.{name} does not exist")
73 else:
74 self._config[name] = value
AttributeError: torch._inductor.config.fx_graph_cache does not exist"
}
The AttributeError you're encountering indicates that torch._inductor.config.fx_graph_cache does not exist in the version of PyTorch you are using. This suggests that the attribute might have been removed, renamed, or is available only in specific versions.
Here’s how you can resolve this issue:
Check PyTorch Documentation:
Look up the PyTorch documentation or release notes for information about changes to the torch._inductor.config attributes. This helps confirm whether the attribute has been deprecated or changed.
Update or Downgrade PyTorch:
Depending on the availability of the fx_graph_cache attribute, you might need to use a specific version of PyTorch.
Remove or Replace Usage:
If fx_graph_cache is not available in the PyTorch version you need to use, you should remove or substitute it with an alternative setting.
Steps:
1. Verify Available Config Options in PyTorch:
You can print the available configuration options:
python
import torch
# Print all available config attributes
print(dir(torch._inductor.config))
Check the above output to see if there's a similar or alternative setting.
2. Remove or Comment Out the Configuration:
If fx_graph_cache is definitely not available and an alternative cannot be found, you might need to remove or comment it out:
In fast_inference_utils.py, either comment out or remove:
python
# torch._inductor.config.coordinate_descent_tuning = True
# torch._inductor.config.triton.unique_kernel_names = True
# torch._inductor.config.fx_graph_cache = (
# True # Experimental feature to reduce compilation times, will be on by default in future
# )
3. Upgrade/Downgrade PyTorch:
Based on your investigation, install the appropriate PyTorch version that supports the required attributes:
sh
pip install torch==<desired-version>
For instance, you might install a specific known compatible version:
sh
pip install torch==2.0.1 triton==2.0.0
4. Reattempt the Code Execution:
After making the changes, rerun your code to see if the error is resolved.
Example requirements.txt with Alternative Configuration:
If you decide to proceed without fx_graph_cache, here’s a modified approach:
Updated fast_inference_utils.py without fx_graph_cache:
python
import torch
# Other imports...
# torch._inductor.config.coordinate_descent_tuning = True
# torch._inductor.config.triton.unique_kernel_names = True
# torch._inductor.config.fx_graph_cache = (
# True # Experimental feature to reduce compilation times, will be on by default in future
# )
# Proceed with other imports and settings
from fam.llm.fast_model import Transformer
Conclusion:
This approach systematically addresses the problem by checking for available configuration settings, ensuring compatibility, and updating code accordingly. This should help in resolving the AttributeError and ensuring smooth functionality of your code with the appropriate PyTorch version.