Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
GGUF loader support for the generic path: stacked F32 .bias expert slices, in-memory override wins in Linear, norm_topk routing (olmoe)
YanissAmz959cf518f9ac
diff --git a/exllamav3/loader/gguf_collection.py b/exllamav3/loader/gguf_collection.pyindex 632f52e..70a3fd1 100644--- a/exllamav3/loader/gguf_collection.py+++ b/exllamav3/loader/gguf_collection.py@@ -146,6 +146,18 @@ class GGUFCollection:mapped = self.name_map.get(key, key)return mapped[0] if isinstance(mapped, tuple) else mapped+ def _exps_slice(self, name: str):+ """"<gguf3d>.e<idx>[.weight|.bias]" -> (stacked tensor name, expert idx) when that stacked tensor exists, else None.+ .bias: stacked F32 bias dims (row, E) (gpt-oss ffn_*_exps.bias), expert idx = one row."""+ sfx = ".bias" if name.endswith(".bias") else ".weight"+ mb = name[:-len(sfx)] if name.endswith(sfx) else name+ if ".e" not in mb:+ return None+ bb_, es_ = mb.rsplit(".e", 1)+ if es_.isdigit() and (bb_ + sfx) in self.infos:+ return bb_ + sfx, int(es_)+ return None+def has_tensor(self, key: str) -> bool:if self._is_aux(key):return self.aux.has_tensor(key)@@ -155,9 +167,7 @@ class GGUFCollection:if r in self.infos:return Trueif "_exps.e" in r: # generic-loader expert slice name: "<gguf3d>.e<idx>[.weight]"- mb = r[:-7] if r.endswith(".weight") else r- bb_, es_ = mb.rsplit(".e", 1)- return es_.isdigit() and (bb_ + ".weight") in self.infos+ return self._exps_slice(r) is not Nonereturn False# Deferred-load arena API (SafetensorsCollection): ForeignLinear and the@@ -250,10 +260,9 @@ class GGUFCollection:mapped, want_T = mapped[0], (mapped[1] == "T")if exp_idx is None and mapped not in self.infos and "_exps.e" in mapped:# engine key mapped by name_map to "<gguf3d>.e<idx>[.weight]" (generic loader): same slice protocol, after the map- mb = mapped[:-7] if mapped.endswith(".weight") else mapped- bb_, es_ = mb.rsplit(".e", 1)- if es_.isdigit() and (bb_ + ".weight") in self.infos:- mapped, exp_idx = bb_ + ".weight", int(es_)+ sl = self._exps_slice(mapped)+ if sl is not None:+ mapped, exp_idx = slinfo = self.infos.get(mapped)if info is None:if not optional:@@ -280,12 +289,16 @@ class GGUFCollection:raise ValueError("transpose not supported for quant payloads")return t.to(dev)if ty in (0, 1, 30): # F32 / F16 / BF16 (BF16 widened to float32: bit shift, exact)- if exp_idx is not None:+ stacked_bias = exp_idx is not None and ty == 0 and mapped.endswith(".bias") and len(dims) == 2+ if exp_idx is not None and not stacked_bias:# Not implemented for float payloads: refuse by name rather than return the whole stack.raise ValueError(f"per-expert slice of a {({0: 'F32', 1: 'F16', 30: 'BF16'})[ty]} "f"stacked tensor is not supported: {mapped} (expert {exp_idx})")dt = np.float32 if ty == 0 else np.float16es = 4 if ty == 0 else 2+ if stacked_bias: # stacked bias (row, E): one expert = one contiguous row of dims[0] values+ assert 0 <= exp_idx < dims[1]+ off, dims = off + exp_idx * dims[0] * es, (dims[0],)n = int(np.prod(dims))raw = self._pread(off, n * es)if ty == 30:diff --git a/exllamav3/modules/block_sparse_mlp.py b/exllamav3/modules/block_sparse_mlp.pyindex 21ca7f2..7748763 100644--- a/exllamav3/modules/block_sparse_mlp.py+++ b/exllamav3/modules/block_sparse_mlp.py@@ -415,9 +415,14 @@ class BlockSparseMLP(BlockSparseMLP_CPU, Module):frange_dim: int = 0,gate_up_interleaved: bool = False,alt_residual_channel: bool = False,- qbits_key: str = "bits"+ qbits_key: str = "bits",+ norm_topk: bool = True):super().__init__(config, key, None)+ # False = router weights are the plain softmax probabilities of the picks (no top-k renormalisation); only the+ # "std" router implements it (pure torch path, see _routing_std_nonorm)+ assert norm_topk or router_type == "std", "norm_topk = False is only implemented for router_type 'std'"+ self.norm_topk = norm_topkself.interm_dtype = interm_dtype# The fused prefill tier (exl3_moe) keeps its gate/up intermediates in fp16 no matter@@ -1417,6 +1422,7 @@ class BlockSparseMLP(BlockSparseMLP_CPU, Module):n_group = self.n_group,topk_group = self.topk_group,per_expert_scale = self.per_expert_scale,+ norm_topk = self.norm_topk,)_prepare_hip_router_gate_t(self.routing_cfg)diff --git a/exllamav3/modules/block_sparse_mlp_routing.py b/exllamav3/modules/block_sparse_mlp_routing.pyindex 2d7bc5b..8ee43bf 100644--- a/exllamav3/modules/block_sparse_mlp_routing.py+++ b/exllamav3/modules/block_sparse_mlp_routing.py@@ -83,6 +83,7 @@ class RoutingCFG:router_logits_gfx12: torch.Tensor | None = Nonerouting_weights_gfx12: torch.Tensor | None = Noneselected_experts_gfx12: torch.Tensor | None = None+ norm_topk: bool = True # False: weights are the full-softmax probabilities of the picks (olmoe), not renormalised_HIP_ROUTER_HIDDEN = 2560@@ -284,6 +285,24 @@ def _routing_nogroup_torch(cfg, y, params, scores):return selected_experts, routing_weights.half()+def _routing_std_nonorm(cfg, y, params):+ """norm_topk=False (llama.cpp olmoe, expert_weights_norm=0): softmax over ALL experts, gather the top-k probabilities, no+ renormalisation. Pure torch for every row count and device (the fused routing_std kernels hard-code the renorm).+ Same stable-sort selection as _routing_std_torch."""+ logits = _router_logits(cfg, y).float()+ probs = torch.softmax(logits, dim = -1)+ if params.get("activate_all_experts"):+ selected_experts = torch.arange(cfg.num_experts, dtype = torch.long, device = y.device).expand(y.shape[0], -1)+ routing_weights = probs+ else:+ _, idx = torch.sort(logits, dim = -1, descending = True, stable = True)+ selected_experts = idx[:, :cfg.num_experts_per_tok].contiguous()+ routing_weights = torch.gather(probs, 1, selected_experts)+ if cfg.per_expert_scale is not None:+ routing_weights = routing_weights * cfg.per_expert_scale.float()[selected_experts]+ return selected_experts, routing_weights.half()++def routing_std(bsz, cfg, y, params):if (gguf_ri("router") and 2 <= bsz <= GGUF_ROW_INV_MAX_ROWS and y.dim() == 2 and y.shape[0] == bszand not params.get("activate_all_experts")):@@ -291,6 +310,8 @@ def routing_std(bsz, cfg, y, params):# logits differ in the last bits and a near tie flips an expert. One one-row routing per row, the bits of the plain step.outs = [routing_std(1, cfg, y[i:i + 1], params) for i in range(bsz)]return torch.cat([o[0].clone() for o in outs]), torch.cat([o[1].clone() for o in outs])+ if not cfg.norm_topk:+ return _routing_std_nonorm(cfg, y, params)if _hip_router_call_supported(bsz, cfg, y, params):_prepare_hip_router_gate_t(cfg)scores, selected_experts, routing_weights = _hip_router_buffers(cfg, bsz)diff --git a/exllamav3/modules/linear.py b/exllamav3/modules/linear.pyindex 8c88da3..bc8d0ad 100644--- a/exllamav3/modules/linear.py+++ b/exllamav3/modules/linear.py@@ -684,6 +684,8 @@ class Linear(Module):g, fm = getattr(self.config, "gguf", None), getattr(self.config, "gguf_formats", None)if g is None or not fm or not isinstance(key, str) or self.is_sliced or self.weight_scale != 1.0:return False+ if os.environ.get("EXL3_GGUF_GENERIC", "0") == "1" and g.new_tensors and (key + ".weight") in g.new_tensors:+ return False # in-memory fp override (e.g. dequantized GDN b/a projs) wins over the stored quant blocksgname = g.name_map.get(key + ".weight")gname = gname[0] if isinstance(gname, tuple) else gnamefrom ..loader.gguf_collection import gguf_fmt as _gguf_fmt