File size: 3,375 Bytes
9834d1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
--- sensenova_loop.pr_orig.py	2026-11-19 08:55:22.831270918 +0530
+++ overlay/vllm/model_executor/models/sensenova_loop.py	2026-11-19 08:55:36.438953456 +0530
@@ -128,9 +128,45 @@
         )
 
 
+def _remap_quant_config_names(quant_config, config) -> None:
+    """Rewrite ModelOpt per-layer names from checkpoint (physical) to vLLM (execution) form.
+
+    The checkpoint names `model.language_model.layers.<physical>.*`; this model builds one
+    module per execution (`model.layers.<execution>.*`), so a looped physical layer maps to
+    several execution prefixes.
+    """
+    destinations: dict[int, list[int]] = {}
+    for execution, physical in enumerate(config.loop_physical_indices):
+        destinations.setdefault(physical, []).append(execution)
+
+    def expand(name: str) -> list[str]:
+        if name.startswith("model.language_model."):
+            name = "model." + name[len("model.language_model.") :]
+        if name.startswith("model.layers."):
+            _, _, index, suffix = name.split(".", 3)
+            if index.isdigit():
+                return [
+                    f"model.layers.{e}.{suffix}" for e in destinations.get(int(index), [])
+                ]
+        return [name]
+
+    excl = getattr(quant_config, "exclude_modules", None)
+    if isinstance(excl, list) and excl:
+        quant_config.exclude_modules = list(
+            dict.fromkeys(n for e in excl for n in [e, *expand(e)])
+        )
+    layers = getattr(quant_config, "quantized_layers", None)
+    if isinstance(layers, dict) and layers:
+        quant_config.quantized_layers = {
+            n: v for k, v in layers.items() for n in [k, *expand(k)]
+        }
+
+
 class SenseNovaLoopForConditionalGeneration(
     nn.Module, HasInnerState, IsHybrid, SupportsMRoPE
 ):
+    packed_modules_mapping = Qwen3_5ForCausalLMBase.packed_modules_mapping
+
     @classmethod
     def get_mamba_state_dtype_from_config(
         cls, vllm_config: VllmConfig
@@ -158,16 +194,18 @@
         self.config = self.model_config.hf_text_config
         if (
             vllm_config.parallel_config.pipeline_parallel_size != 1
-            or vllm_config.quant_config is not None
             or vllm_config.speculative_config is not None
             or vllm_config.lora_config is not None
             or getattr(self.config, "layer_scale", False)
         ):
             raise ValueError(
-                "SenseNova Loop currently requires unquantized text inference "
+                "SenseNova Loop currently requires text inference "
                 "without pipeline parallelism, LoRA, speculation or layer_scale"
             )
-        self.quant_config = None
+        # Local patch: allow (ModelOpt) quantized checkpoints.
+        self.quant_config = vllm_config.quant_config
+        if self.quant_config is not None:
+            _remap_quant_config_names(self.quant_config, self.config)
         self.scheduler_config = vllm_config.scheduler_config
         self.model = SenseNovaLoopModel(
             vllm_config=vllm_config, prefix=maybe_prefix(prefix, "model")
@@ -175,6 +213,7 @@
         self.lm_head = ParallelLMHead(
             self.config.vocab_size,
             self.config.hidden_size,
+            quant_config=self.quant_config,
             prefix=maybe_prefix(prefix, "lm_head"),
         )
         if self.config.tie_word_embeddings: