Image-Text-to-Text
Transformers
Safetensors
mage_vl
text-generation
mage-vl
vision-language-model
quantization
xpo3
runtime-v2
nvfp4
w4a4
w4a16
blackwell
conversational
custom_code
8-bit precision
Instructions to use ajh-code/Mage-VL-XPO3-NVFP4-W4A4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ajh-code/Mage-VL-XPO3-NVFP4-W4A4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="ajh-code/Mage-VL-XPO3-NVFP4-W4A4", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("ajh-code/Mage-VL-XPO3-NVFP4-W4A4", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ajh-code/Mage-VL-XPO3-NVFP4-W4A4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ajh-code/Mage-VL-XPO3-NVFP4-W4A4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ajh-code/Mage-VL-XPO3-NVFP4-W4A4", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/ajh-code/Mage-VL-XPO3-NVFP4-W4A4
- SGLang
How to use ajh-code/Mage-VL-XPO3-NVFP4-W4A4 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ajh-code/Mage-VL-XPO3-NVFP4-W4A4" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ajh-code/Mage-VL-XPO3-NVFP4-W4A4", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ajh-code/Mage-VL-XPO3-NVFP4-W4A4" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ajh-code/Mage-VL-XPO3-NVFP4-W4A4", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use ajh-code/Mage-VL-XPO3-NVFP4-W4A4 with Docker Model Runner:
docker model run hf.co/ajh-code/Mage-VL-XPO3-NVFP4-W4A4
| #!/usr/bin/env python3 | |
| """Validate a packaged Mage-VL FP8 or NVFP4 Hugging Face repository.""" | |
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| from safetensors import safe_open | |
| ROOT = Path(__file__).resolve().parent | |
| def sha256(path: Path) -> str: | |
| digest = hashlib.sha256() | |
| with path.open("rb") as handle: | |
| for chunk in iter(lambda: handle.read(8 * 1024 * 1024), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def fail(message: str) -> None: | |
| raise RuntimeError(message) | |
| def main() -> None: | |
| config = json.loads((ROOT / "config.json").read_text(encoding="utf-8")) | |
| quantization = config.get("mage_vl_quantization") | |
| if not isinstance(quantization, dict): | |
| fail("config.json has no mage_vl_quantization dictionary") | |
| format_name = quantization.get("format") | |
| if format_name not in {"scaled_fp8_w8a8", "native_nvfp4_w4a4"}: | |
| fail(f"unsupported quantization format: {format_name}") | |
| if format_name == "native_nvfp4_w4a4": | |
| if quantization.get("runtime_version") != 2: | |
| fail("NVFP4 release must declare runtime_version 2") | |
| if quantization.get("default_profile") != "hybrid_fast": | |
| fail("NVFP4 default_profile must be hybrid_fast") | |
| profiles = quantization.get("runtime_profiles") | |
| if not isinstance(profiles, dict): | |
| fail("NVFP4 release has no runtime_profiles dictionary") | |
| if set(profiles) != {"hybrid_fast", "pure_w4a4_v2"}: | |
| fail(f"unexpected NVFP4 runtime profiles: {sorted(profiles)}") | |
| hybrid = profiles["hybrid_fast"] | |
| pure = profiles["pure_w4a4_v2"] | |
| if hybrid.get("smallm_backend") != "w4a16_gemv": | |
| fail("hybrid_fast must select w4a16_gemv") | |
| if hybrid.get("shared_gate_up_activation") or hybrid.get( | |
| "shared_qkv_activation" | |
| ): | |
| fail("hybrid_fast must not enable shared W4A4 activations") | |
| if pure.get("smallm_backend") != "off": | |
| fail("pure_w4a4_v2 must disable the W4A16 small-M backend") | |
| if not pure.get("shared_gate_up_activation") or not pure.get( | |
| "shared_qkv_activation" | |
| ): | |
| fail("pure_w4a4_v2 must enable both shared W4A4 activations") | |
| index = json.loads( | |
| (ROOT / "model.safetensors.index.json").read_text(encoding="utf-8") | |
| ) | |
| weight_map = index.get("weight_map") | |
| if not isinstance(weight_map, dict) or not weight_map: | |
| fail("checkpoint index has no weight map") | |
| shard_names = sorted(set(weight_map.values())) | |
| discovered: dict[str, str] = {} | |
| logical_size = 0 | |
| for shard_name in shard_names: | |
| shard_path = ROOT / shard_name | |
| if not shard_path.is_file(): | |
| fail(f"missing checkpoint shard: {shard_name}") | |
| with safe_open(shard_path, framework="pt", device="cpu") as handle: | |
| for key in handle.keys(): | |
| if key in discovered: | |
| fail(f"duplicate tensor across shards: {key}") | |
| discovered[key] = shard_name | |
| tensor_slice = handle.get_slice(key) | |
| shape = tensor_slice.get_shape() | |
| dtype = tensor_slice.get_dtype() | |
| element_sizes = { | |
| "BF16": 2, | |
| "F32": 4, | |
| "F8_E4M3": 1, | |
| "U8": 1, | |
| } | |
| if dtype not in element_sizes: | |
| fail(f"unsupported validation dtype {dtype} for {key}") | |
| elements = 1 | |
| for dimension in shape: | |
| elements *= dimension | |
| logical_size += elements * element_sizes[dtype] | |
| if discovered != weight_map: | |
| missing = sorted(set(weight_map) - set(discovered)) | |
| extra = sorted(set(discovered) - set(weight_map)) | |
| fail(f"checkpoint index mismatch; missing={missing[:3]} extra={extra[:3]}") | |
| if logical_size != int(index["metadata"]["total_size"]): | |
| fail( | |
| f"logical checkpoint size mismatch: {logical_size} != " | |
| f"{index['metadata']['total_size']}" | |
| ) | |
| qdata = [key for key in weight_map if key.endswith(".qdata")] | |
| scales = [key for key in weight_map if key.endswith(".weight_scale")] | |
| block_scales = [ | |
| key for key in weight_map if key.endswith(".weight_block_scale") | |
| ] | |
| if len(qdata) != 252 or len(scales) != 252: | |
| fail( | |
| f"expected 252 qdata/scales, got {len(qdata)}/{len(scales)}" | |
| ) | |
| if format_name == "native_nvfp4_w4a4" and len(block_scales) != 252: | |
| fail(f"expected 252 NVFP4 block scales, got {len(block_scales)}") | |
| if format_name == "scaled_fp8_w8a8" and block_scales: | |
| fail("FP8 checkpoint unexpectedly contains NVFP4 block scales") | |
| manifest = json.loads((ROOT / "MANIFEST.json").read_text(encoding="utf-8")) | |
| for record in manifest.get("files", []): | |
| path = ROOT / record["path"] | |
| if not path.is_file(): | |
| fail(f"manifest file is missing: {record['path']}") | |
| if path.stat().st_size != record["size"]: | |
| fail(f"manifest size mismatch: {record['path']}") | |
| if sha256(path) != record["sha256"]: | |
| fail(f"manifest hash mismatch: {record['path']}") | |
| print( | |
| json.dumps( | |
| { | |
| "status": "pass", | |
| "format": format_name, | |
| "checkpoint_tensors": len(weight_map), | |
| "checkpoint_shards": len(shard_names), | |
| "checkpoint_logical_bytes": logical_size, | |
| "quantized_language_projections": len(qdata), | |
| "manifest_files": len(manifest.get("files", [])), | |
| }, | |
| indent=2, | |
| ) | |
| ) | |
| if __name__ == "__main__": | |
| main() | |