Skip to content

fix(mistral): guard ReasoningEffort import for older mistral_common versions#45378

Open
hijingsong wants to merge 1 commit intohuggingface:mainfrom
hijingsong:clawoss/fix/reasoning-effort-import-guard
Open

fix(mistral): guard ReasoningEffort import for older mistral_common versions#45378
hijingsong wants to merge 1 commit intohuggingface:mainfrom
hijingsong:clawoss/fix/reasoning-effort-import-guard

Conversation

@hijingsong
Copy link
Copy Markdown

Fix: Guard ReasoningEffort import for older mistral_common versions

Fixes #45372

Problem

ReasoningEffort was added in mistral-common>=1.10.0, but the import in tokenization_mistral_common.py was unconditional within the is_mistral_common_available() guard. Users with mistral-common<1.10.0 would get an ImportError that prevented loading any processor — including non-Mistral models like Gemma 4 and Qwen.

Additionally, even stubbing ReasoningEffort = None was insufficient because line 1042 uses ReasoningEffort | None in a type annotation, causing TypeError: unsupported operand type(s) for | since NoneType does not support the | operator.

Fix

Wrap the ReasoningEffort import in a try/except ImportError, falling back to typing.Any. This ensures:

  1. The module loads regardless of mistral-common version
  2. The ReasoningEffort | None type annotation resolves correctly (Any | None is valid)
  3. Non-Mistral models work without requiring the latest mistral-common
  4. Mistral models with reasoning_effort support work correctly when mistral-common>=1.10.0 is installed

Changes

  • src/transformers/tokenization_mistral_common.py: Split the combined import of ChatCompletionRequest and ReasoningEffort into separate imports with a try/except guard

Testing

  • Syntax validation passes
  • Type annotation Any | None resolves correctly at runtime
  • No changes to runtime behavior for users with mistral-common>=1.10.0

…ersions

ReasoningEffort was added in mistral-common 1.10.0 but the import was
unconditional within the is_mistral_common_available() guard. Users with
mistral-common < 1.10.0 would get an ImportError that prevented loading
any processor, including non-Mistral models like Gemma 4.

Wrap the ReasoningEffort import in a try/except, falling back to
typing.Any so the type annotation at line 1042 still resolves.

Fixes huggingface#45372
@zucchini-nlp
Copy link
Copy Markdown
Member

zucchini-nlp commented Apr 13, 2026

We have pinned it to 1.10.0 so ig you need to re-install to get the updated version

"mistral-common[image]>=1.10.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImportError: cannot import name 'ReasoningEffort' from mistral_common breaks Gemma 4 processor loading in transformers 5.5.x / 5.6.0.dev0

2 participants