Maxluria Claude Opus 4.8 commited on
Commit
7b3f3c2
·
1 Parent(s): 3e26dc8

Shim is_torch_fx_available instead of pinning transformers down

Browse files

Pinning transformers to the 4.56 line (for MiniCPM) is impossible in this env:
it requires huggingface-hub<1.0 while Gradio 6.18 requires >=1.0. Keep
transformers current and restore the is_torch_fx_available symbol that
MiniCPM4.1-8B's bundled modeling code imports, before any remote code runs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (2) hide show
  1. app.py +19 -0
  2. requirements.txt +4 -3
app.py CHANGED
@@ -20,6 +20,25 @@ import spaces
20
  import torch
21
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  from shards import SHARD_ORDER, SHARDS
24
 
25
  # ---------------------------------------------------------------------------- #
 
20
  import torch
21
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
22
 
23
+ # Compatibility shim: MiniCPM4.1-8B's bundled modeling code does
24
+ # `from transformers.utils.import_utils import is_torch_fx_available`, which newer
25
+ # transformers removed from that module. We can't pin transformers down (Gradio
26
+ # 6.18 needs huggingface-hub>=1.0, which the old transformers line conflicts
27
+ # with), so we restore the symbol before any remote code runs.
28
+ import transformers.utils.import_utils as _iu # noqa: E402
29
+ if not hasattr(_iu, "is_torch_fx_available"):
30
+ try:
31
+ from transformers.utils import is_torch_fx_available as _fx # type: ignore
32
+ except Exception:
33
+ try:
34
+ import torch.fx # noqa: F401
35
+ def _fx(): # torch.fx imports fine -> treat as available
36
+ return True
37
+ except Exception:
38
+ def _fx():
39
+ return False
40
+ _iu.is_torch_fx_available = _fx
41
+
42
  from shards import SHARD_ORDER, SHARDS
43
 
44
  # ---------------------------------------------------------------------------- #
requirements.txt CHANGED
@@ -1,7 +1,8 @@
1
  gradio
2
  spaces
3
- # MiniCPM4.1-8B's bundled modeling code imports is_torch_fx_available, which
4
- # newer transformers removed; pin to the 4.56 line OpenBMB tested against.
5
- transformers>=4.56,<4.57
 
6
  torch
7
  accelerate
 
1
  gradio
2
  spaces
3
+ # Keep transformers current (Gradio 6.18 needs huggingface-hub>=1.0, which the
4
+ # old 4.56 line conflicts with). MiniCPM's bundled code expects an older symbol
5
+ # (is_torch_fx_available) that we shim in app.py instead of downgrading.
6
+ transformers>=4.51.0
7
  torch
8
  accelerate