SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · Li_MBQ_Modality-Balanced_Quantization_for_Large_Vision-Language_Models_CVPR_2025_paper · CVPR · 2025

MBQ: Modality-Balanced Quantization for Large Vision-Language Models

Xuefei Ning, Huazhong Yang, Yu Wang, Xihui Liu, Shiyao Li, Guohao Dai, Shengen Yan, Xiuhong Li, Yingchun Hu, Ke Hong, Xiaotao Jia, Yaqi Yan, and 1 more

Open in the Atlas

Code that ran

9 of 11 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 3 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 6 failures of our instrument; 2 no recorded run), measured 2026-11-22; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/Li_MBQ_Modality-Balanced_Quantization_for_Large_Vision-Language_Models_CVPR_2025_paper.json · badge: /api/ran/Li_MBQ_Modality-Balanced_Quantization_for_Large_Vision-Language_Models_CVPR_2025_paper.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
thu-nics/MBQ canonical (classifier label)
classifier basis: census
9 ran · 2 no recorded run
FunctionStatusWhere it lives
calculate_zeros_width Ran
ran, honoured the contract we drafted
thu-nics/MBQ/qmllm/methods/mbq/quantize/qmodule.py
code served (permissive licence) · get_code("fd8719af3db2c5ae")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# Analyze the function:
# calculate_zeros_width takes:
# - in_features: an integer (used in arithmetic operations)
# - group_size: an integer with default 128 (used in conditionals and arithmetic)
# - pack_num: an integer with default 8 (used in arithmetic)
# 
# The function performs integer arithmetic and conditional logic.
# No objects or methods are called, just arithmetic operations.

ARGS = {
    "in_features": 256,
    "group_size": 128,
    "pack_num": 8,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_act_scale Ran
ran; our contract draft was wrong, not the code
thu-nics/MBQ/qmllm/methods/mbq/quantize/auto_scale.py
code served (permissive licence) · get_code("0fbb308a9e0be4b1")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 1, dtype family float, shape (4,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# The function get_act_scale expects a tensor x
# It calls:
# - x.abs() to get absolute values
# - .view(-1, x.shape[-1]) to reshape to (flattened, last_dim)
# - .mean(0) to compute mean along dimension 0
# So x should be a multi-dimensional tensor with at least 2 dimensions

# Create a small tensor: shape (2, 3, 4) where last dim is 4
x = torch.randn(2, 3, 4)

ARGS = {
    "x": x
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (4,) — shape (4,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_module_by_name_suffix Ran
ran; our contract draft was wrong, not the code
thu-nics/MBQ/qmllm/methods/mbq/quantize/quantizer.py
code served (permissive licence) · get_code("0ae488b77c73c6a6")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Linear. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Build a simple model with named modules
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.layer1 = nn.Linear(4, 3)
        self.layer2 = nn.Linear(3, 2)
        self.layer2.sublayer = nn.Linear(2, 1)
    
    def forward(self, x):
        return x

model = SimpleModel()

# The function uses:
# - model.named_modules() - requires a nn.Module
# - module_name endswith check - requires a string
# - returns a module if found

ARGS = {
    "model": model,
    "module_name": "layer2"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Linear — a Linear output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Linear output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_multimodal_calib_dataset Ran
ran; our contract draft was wrong, not the code
thu-nics/MBQ/qmllm/calibration/coco_vl.py
code served (permissive licence) · get_code("48fdfb9c1dfa6dee")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import os
import json
import torch
import numpy as np
from PIL import Image
from io import BytesIO

torch.manual_seed(0)

# Create a minimal mock model
class MockModel(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.tokenizer = MockTokenizer()
    
    def preprocess_data(self, images, data_item):
        # Return a dict with minimal data
        return {
            'input_ids': torch.tensor([[1, 2, 3, 4]], dtype=torch.long),
            'attention_mask': torch.tensor([[1, 1, 1, 1]], dtype=torch.long),
        }
    
    def data_collator(self, data_list):
        # Collate a batch of preprocessed data
        return {
            'input_ids': torch.cat([d['input_ids'] for d in data_list], dim=0),
            'attention_mask': torch.cat([d['attention_mask'] for d in data_list], dim=0),
        }
    
    def few_shot_data_samples(self, examples):
        # Return modified examples for few-shot format
        return examples
    
    def interleave_data_samples(self, examples, pure_text=None):
        # Return modified examples for interleave format
        return examples
    
    def generate_input(self, examples):
        # Return prompt inputs and kwargs
        prompt_inputs = torch.tensor([[1, 2, 3, 4]])
        prompt_kwargs = {'attention_mask': torch.tensor([[1, 1, 1, 1]])}
        return (prompt_inputs, prompt_kwargs)

class MockTokenizer:
    def encode(self, text):
        # Return a simple token list
        return [1, 2, 3] * 200  # Enough tokens to test the 512 limit

# Create a temporary directory and files for testing
import tempfile
temp_dir = tempfile.mkdtemp()

# Create a simple test image
def create_test_image():
    img = Image.new('RGB', (32, 32), color=(73, 109, 137))
    return img

# Create image folder and test images
image_folder = os.path.join(temp_dir, 'images')
os.makedirs(image_folder, exist_ok=True)

# Save test images
img1 = create_test_image()
img1_path = os.path.join(image_folder, 'test_image_1.jpg')
img1.save(img1_path)

img2 = create_test_image()
img2_path = os.path.join(image_folder, 'test_image_2.jpg')
img2.save(img2_path)

# Create a test data file (JSONL format)
data_path = os.path.join(temp_dir, 'test_data.jsonl')
test_data = [
    {'image': 'test_image_1.jpg', 'text': 'A description of image 1'},
    {'image': ['test_image_1.jpg', 'test_image_2.jpg'], 'text': 'A description of multiple images'},
    {'image': 'test_image_2.jpg', 'text': 'A description of image 2'},
]

with open(data_path, 'w') as f:
    for item in test_data:
        f.write(json.dumps(item) + '\n')

# Create mock model
model = MockModel()

ARGS = {
    'data_path': data_path,
    'image_folder': image_folder,
    'model': model,
    'n_samples': 2,
    'few_shot_format': False,
    'interleave_format': False,
    'text_data_path': None,
    'shuffle': True,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, datasets, numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_named_linears Ran
ran; our contract draft was wrong, not the code
thu-nics/MBQ/qmllm/methods/mbq/quantize/pre_quant.py
code served (permissive licence) · get_code("0310065bdf9208bb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a simple neural network module with Linear layers
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.linear2 = nn.Linear(3, 2)
        self.relu = nn.ReLU()
        self.linear3 = nn.Linear(2, 1)
    
    def forward(self, x):
        x = self.linear1(x)
        x = self.relu(x)
        x = self.linear2(x)
        x = self.linear3(x)
        return x

module = SimpleModel()

ARGS = {
    "module": module
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_weight_scale Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
thu-nics/MBQ/qmllm/methods/mbq/quantize/auto_scale.py
code served (permissive licence) · get_code("ec909faceaba76f5")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 1, dtype family float, shape (3,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create a small weight tensor
# Shape: (4, 3) - distinct dimensions for probing
weight = torch.randn(4, 3)

# Test with q_group_size=-1 (default case)
q_group_size = -1

ARGS = {
    "weight": weight,
    "q_group_size": q_group_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (3,) — shape (3,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_image Ran
ran, honoured the contract we drafted
thu-nics/MBQ/qmllm/calibration/coco_vl.py
code served (permissive licence) · get_code("0921f960e75f4e82")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Image. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tempfile
from PIL import Image
import os

# Create a temporary directory and a simple test image
temp_dir = tempfile.mkdtemp()
image_path = os.path.join(temp_dir, "test_image.png")

# Create a small RGB image and save it
test_image = Image.new('RGB', (4, 3), color=(255, 0, 0))
test_image.save(image_path)

ARGS = {
    'image_path': image_path
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Image — a Image output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Image output the recorded ndim 3 and dtype family int describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
make_divisible Ran
ran, honoured the contract we drafted
thu-nics/MBQ/qmllm/methods/mbq/quantize/qmodule.py
code served (permissive licence) · get_code("ad85b288e9acb9c2")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

ARGS = {
    "c": 10,
    "divisor": 3
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
process_input Ran
ran; our contract draft was wrong, not the code
thu-nics/MBQ/qmllm/methods/mbq/quantize/pre_quant.py
code served (permissive licence) · get_code("72644f3889bd62df")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Construct prompt_inputs dictionary
prompt_inputs = {
    'input_ids': torch.randint(0, 100, (2, 8)),
    'attention_mask': torch.ones((2, 8)),
    'token_type_ids': torch.zeros((2, 8)),
}

# Construct prompt_kwargs dictionary with optional vision_mask and caption_mask
prompt_kwargs = {
    'vision_mask': torch.ones((2, 16)),
    'caption_mask': torch.ones((2, 4)),
}

ARGS = {
    'prompt_inputs': prompt_inputs,
    'prompt_kwargs': prompt_kwargs,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_blocks Not yet run
unverified (harvested, no recorded run)
thu-nics/MBQ/qmllm/methods/mbq/quantize/pre_quant.py
code served (permissive licence) · get_code("a2bf10bce9b439aa")
How it ran

no invocation recorded.

get_calib_dataset Not yet run
unverified (harvested, no recorded run)
thu-nics/MBQ/qmllm/calibration/pileval.py
code served (permissive licence) · get_code("fea5dc12fc287c8a")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 6 are also present in other papers whose code we hold (6 with at least one paper dated earlier, 0 the same month, 0 later) and 5 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
calculate_zeros_width 3 other papers
3 dated earlier
2402.02750 (2024-02)
KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
2402.10631 (2024-02)
BitDistiller: Unleashing the Potential of Sub-4-Bit LLMs via Self-Distillation
2403.05527 (2024-03)
GEAR: An Efficient KV Cache Compression Recipe for Near-Lossless Generative Inference of LLM
make_divisible 3 other papers
3 dated earlier
2402.02750 (2024-02)
KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
2402.10631 (2024-02)
BitDistiller: Unleashing the Potential of Sub-4-Bit LLMs via Self-Distillation
2403.05527 (2024-03)
GEAR: An Efficient KV Cache Compression Recipe for Near-Lossless Generative Inference of LLM
get_act_scale 1 other paper
1 dated earlier
2402.18158 (2024-02)
Evaluating Quantized Large Language Models
get_module_by_name_suffix 1 other paper
1 dated earlier
2402.18158 (2024-02)
Evaluating Quantized Large Language Models
get_named_linears 1 other paper
1 dated earlier
2402.10631 (2024-02)
BitDistiller: Unleashing the Potential of Sub-4-Bit LLMs via Self-Distillation
get_weight_scale 1 other paper
1 dated earlier
2402.18158 (2024-02)
Evaluating Quantized Large Language Models

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Vision-Language Models (VLMs) have enabled a variety of real-world applications. The large parameter size of VLMs brings large memory and computation overhead which poses significant challenges for deployment. Post-Training Quantization (PTQ) is an effective technique to reduce the memory and computation overhead. Existing PTQ methods mainly focus on large language models (LLMs), without considering the differences across other modalities. In this paper, we discover that there is a significant difference in sensitivity between language and vision tokens in large VLMs. Therefore, treating tokens from different modalities equally, as in existing PTQ methods, may over-emphasize the insensitive modalities, leading to significant accuracy loss. To deal with the above issue, we propose a simple yet effective method, Modality-Balanced Quantization (MBQ), for large VLMs. Specifically, MBQ incorporates the different sensitivities across modalities during the calibration process to minimize the reconstruction loss for better quantization parameters. Extensive experiments show that MBQ can significantly improve task accuracy by up to 4.4% and 11.6% under W3A16 and W4A8 quantization for 7B to 70B VLMs, compared to SOTA baselines. Additionally, we implement a W3A16 GPU kernel that fuses the dequantization and GEMV operators, achieving a 1.4→ speedup on LLaVAonevision-7B on the RTX 4090. The code is available at https://github.com/thu-nics/MBQ.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("Li_MBQ_Modality-Balanced_Quantization_for_Large_Vision-Language_Models_CVPR_2025_paper")
get_code_for_paper("Li_MBQ_Modality-Balanced_Quantization_for_Large_Vision-Language_Models_CVPR_2025_paper")
have("Li_MBQ_Modality-Balanced_Quantization_for_Large_Vision-Language_Models_CVPR_2025_paper")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/Li_MBQ_Modality-Balanced_Quantization_for_Large_Vision-Language_Models_CVPR_2025_paper.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/Li_MBQ_Modality-Balanced_Quantization_for_Large_Vision-Language_Models_CVPR_2025_paper.svg)](https://syntology.ai/paper/Li_MBQ_Modality-Balanced_Quantization_for_Large_Vision-Language_Models_CVPR_2025_paper)

Connect an agent — have() is free.