Kaggle: ImportError: cannot import name 'is_torch_fx_available' from 'transformers.utils.import_utils'
Have you used the Transformers version specified in the README?
Also, could you please share the complete code snippet you’re using where you’re encountering this error?
Back then, I was trying on Kaggle.
I have shifted to a local GPU, and there has been no issue.
Here is the code snippet I used in Kaggle:
from transformers import AutoConfig, pipeline
import transformers.utils.import_utils as import_utils
1. First, apply the previous hotfix for the Import Error
if not hasattr(import_utils, "is_torch_fx_available"):
import_utils.is_torch_fx_available = lambda: False
2. Load the config and fix the RoPE type mismatch
model_id = "bharatgenai/Param2-17B-A2.4B-Thinking"
config = AutoConfig.from_pretrained(model_id, trust_remote_code=True)
The script expects a specific key; 'llama' or 'linear' are common defaults
for these architectures if 'default' is failing.
if not hasattr(config, "rope_type") or config.rope_type == "default":
config.rope_type = "linear" # Or "llama", depending on the base architecture
3. Load the pipeline with the corrected config
pipe = pipeline(
"text-generation",
model=model_id,
config=config,
trust_remote_code=True,
device_map="auto" # Recommended for a 17B model
)
messages = [{"role": "user", "content": "Who are you?"}]
print(pipe(messages))
Python: 3.12
Library: transformers (latest) - In the Readme no specific version was mentioned