TeamNull commited on
Commit
081e691
·
verified ·
1 Parent(s): 691757c

Score 1.6-3.1B models: SmolLM3-3B, Qwen3.5-2B, LFM3-1.7B, granite-1B

Browse files
Files changed (1) hide show
  1. bench_deeparithmark.py +68 -0
bench_deeparithmark.py CHANGED
@@ -29,8 +29,10 @@ Usage
29
  from __future__ import annotations
30
 
31
  import argparse
 
32
  import gc
33
  import hashlib
 
34
  import json
35
  import math
36
  import time
@@ -42,6 +44,72 @@ import torch.nn.functional as F
42
  from huggingface_hub import hf_hub_download
43
  from transformers import AutoModelForCausalLM, AutoTokenizer
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  # Our own data is read from disk; this repo is not published under AxiomicLabs.
46
  DATA_DEFAULT = "deeparithmark-dataset/data/deeparithmark-1.jsonl"
47
  # The one AxiomicLabs reference that must stay: `--compare` downloads the upstream
 
29
  from __future__ import annotations
30
 
31
  import argparse
32
+ import functools
33
  import gc
34
  import hashlib
35
+ import inspect
36
  import json
37
  import math
38
  import time
 
44
  from huggingface_hub import hf_hub_download
45
  from transformers import AutoModelForCausalLM, AutoTokenizer
46
 
47
+ # Some 2026 checkpoints ship remote modelling code written against transformers 4.x
48
+ # (e.g. LiquidAI/LFM3, which decorates its convolution with a hub-kernel helper).
49
+ # transformers 5 removed that helper, so the import fails before the model can load.
50
+ # The decorator only swaps in an optional fused CUDA kernel; stubbing it out leaves
51
+ # the pure-torch path, which is the same maths at the same dtype.
52
+ def _accepts_layer_idx(fn) -> bool:
53
+ try:
54
+ return "layer_idx" in inspect.signature(fn).parameters
55
+ except (TypeError, ValueError):
56
+ return True
57
+
58
+
59
+ def _install_kernel_decorator_shim() -> None:
60
+ try:
61
+ import transformers.integrations as ti
62
+
63
+ if not hasattr(ti, "use_kernel_func_from_hub_with_fallback"):
64
+ def _noop(*_args, **_kwargs):
65
+ return lambda fn: fn
66
+
67
+ ti.use_kernel_func_from_hub_with_fallback = _noop
68
+
69
+ import transformers.integrations.accelerate as tia
70
+
71
+ if not hasattr(tia, "force_accelerate_hooks"):
72
+ def _noop_hooks(*_args, **_kwargs):
73
+ return lambda fn: fn
74
+
75
+ tia.force_accelerate_hooks = _noop_hooks
76
+
77
+ import transformers.masking_utils as tmu
78
+
79
+ if not hasattr(tmu, "create_recurrent_attention_mask"):
80
+ # transformers 4.x used this to hand a conv/linear-attention layer the plain
81
+ # 2-D padding mask (1 = real token). It was deleted in 5.x; the contiguity
82
+ # logic LFM3 needs on top of it (`seq_idx`) is computed in the model itself.
83
+ def _recurrent_mask(config=None, inputs_embeds=None, attention_mask=None,
84
+ past_key_values=None, position_ids=None, layer_idx=None,
85
+ **_kwargs):
86
+ if attention_mask is None:
87
+ return None
88
+ return attention_mask.to(torch.bool) if attention_mask.dtype != torch.bool else attention_mask
89
+
90
+ tmu.create_recurrent_attention_mask = _recurrent_mask
91
+
92
+ if not _accepts_layer_idx(tmu.create_causal_mask):
93
+ # 5.5 picks the layer's mask from the hybrid cache itself, so the explicit
94
+ # `layer_idx` LFM3 passes is redundant rather than meaningful: drop it.
95
+ def _wrap_drop_layer_idx(fn):
96
+ @functools.wraps(fn)
97
+ def wrapper(*args, layer_idx=None, **kwargs):
98
+ del layer_idx
99
+ return fn(*args, **kwargs)
100
+
101
+ return wrapper
102
+
103
+ tmu.create_causal_mask = _wrap_drop_layer_idx(tmu.create_causal_mask)
104
+ tmu.create_sliding_window_causal_mask = _wrap_drop_layer_idx(
105
+ tmu.create_sliding_window_causal_mask
106
+ )
107
+ except Exception: # an old transformers that has the real helper is fine too
108
+ pass
109
+
110
+
111
+ _install_kernel_decorator_shim()
112
+
113
  # Our own data is read from disk; this repo is not published under AxiomicLabs.
114
  DATA_DEFAULT = "deeparithmark-dataset/data/deeparithmark-1.jsonl"
115
  # The one AxiomicLabs reference that must stay: `--compare` downloads the upstream