@@ -83,6 +83,7 @@ def build_from_gguf(
8383 dtype : str | None = None ,
8484 keep_quantized : bool = False ,
8585 execution_provider : str = "default" ,
86+ mmproj : str | Path | None = None ,
8687) -> ModelPackage :
8788 """Build an ONNX :class:`ModelPackage` from a GGUF file.
8889
@@ -116,6 +117,12 @@ def build_from_gguf(
116117 optimisations (e.g. ``"cpu"`` to apply the
117118 GroupQueryAttention rewrite). Defaults to ``"default"``
118119 (portable, no vendor fusions).
120+ mmproj: Optional path (or HF ref) to a companion ``clip``
121+ multimodal-projector GGUF. When set, this becomes the single
122+ entry point for a multimodal build: the text GGUF and the
123+ mmproj vision/audio encoder are fused into one multimodal
124+ :class:`ModelPackage` (delegates to
125+ :func:`build_gemma4_vlm_from_gguf`).
119126
120127 Returns:
121128 A :class:`ModelPackage` containing the built model(s).
@@ -127,6 +134,20 @@ def build_from_gguf(
127134 """
128135 import dataclasses
129136
137+ # A companion mmproj GGUF turns this into a multimodal build: the text +
138+ # vision/audio encoders are assembled by the dedicated VLM builder. Keep
139+ # build_from_gguf as the single public entry point (text-only or multimodal).
140+ if mmproj is not None :
141+ from mobius .integrations .gguf ._mmproj import build_gemma4_vlm_from_gguf
142+
143+ return build_gemma4_vlm_from_gguf (
144+ gguf_path ,
145+ mmproj ,
146+ dtype = dtype ,
147+ execution_provider = execution_provider ,
148+ keep_quantized = keep_quantized ,
149+ )
150+
130151 from mobius ._builder import (
131152 build_from_module ,
132153 resolve_dtype ,
@@ -509,6 +530,68 @@ def _require_supported_requantization(
509530 )
510531
511532
533+ def repack_gguf_weight_to_target (
534+ gguf_model ,
535+ raw ,
536+ qtype ,
537+ np_shape ,
538+ * ,
539+ target_bits : int ,
540+ target_block_size : int ,
541+ target_symmetric : bool ,
542+ tensor_name : str ,
543+ ):
544+ """Repack one 2-D GGUF weight to the graph's common MatMulNBits target.
545+
546+ Reuses the shared repacker machinery: a tensor whose native repacked layout
547+ already matches ``(target_bits, target_block_size)`` is repacked directly;
548+ otherwise it is dequantized and requantized to the target layout. This is
549+ the single-tensor building block reused by both the text-only
550+ (:func:`_load_quantized_state_dict`) and the multimodal quantized loaders.
551+
552+ Args:
553+ gguf_model: The source :class:`GGUFModel`.
554+ raw: Raw tensor bytes (as returned by ``tensor_items_raw``).
555+ qtype: The GGUF quantization type of the tensor.
556+ np_shape: The tensor's logical ``(N, K)`` shape.
557+ target_bits: Target MatMulNBits bit width.
558+ target_block_size: Target MatMulNBits block size.
559+ target_symmetric: Whether the requantization path should omit
560+ zero-points (symmetric). Only used when requantizing.
561+ tensor_name: Name used for error messages.
562+
563+ Returns:
564+ A ``RepackedTensor`` with the target ``(bits, block_size)`` layout.
565+ """
566+ import numpy as np
567+
568+ from mobius .integrations .gguf ._repacker import (
569+ can_repack ,
570+ repack_dequantized_tensor ,
571+ repack_gguf_tensor ,
572+ )
573+
574+ qtype_val = qtype .value if hasattr (qtype , "value" ) else qtype
575+ if can_repack (qtype_val ):
576+ shape_2d = (int (np_shape [0 ]), int (np_shape [1 ]))
577+ repacked = repack_gguf_tensor (raw .ravel ().view (np .uint8 ), qtype_val , shape_2d )
578+ if repacked .bits == target_bits and repacked .block_size == target_block_size :
579+ return repacked
580+
581+ _require_supported_requantization (
582+ bits = target_bits ,
583+ block_size = target_block_size ,
584+ tensor_name = tensor_name ,
585+ )
586+ values = gguf_model .dequantize_raw_tensor (raw , qtype , np_shape )
587+ return repack_dequantized_tensor (
588+ values ,
589+ bits = target_bits ,
590+ block_size = target_block_size ,
591+ symmetric = target_symmetric ,
592+ )
593+
594+
512595def _load_dequantized_state_dict (
513596 gguf_model ,
514597 gguf_arch : str ,
0 commit comments