Instructions to use tiny-random/hy4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/hy4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tiny-random/hy4") 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)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("tiny-random/hy4") model = AutoModelForMultimodalLM.from_pretrained("tiny-random/hy4", device_map="auto") 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?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/hy4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/hy4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/hy4", "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/tiny-random/hy4
- SGLang
How to use tiny-random/hy4 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 "tiny-random/hy4" \ --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": "tiny-random/hy4", "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 "tiny-random/hy4" \ --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": "tiny-random/hy4", "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 tiny-random/hy4 with Docker Model Runner:
docker model run hf.co/tiny-random/hy4
This is a randomly initialized tiny model based on tencent/Hy4 for testing and debugging.
| Feature | Source | This repo |
|---|---|---|
| Checkpoint tensor elements | 774.40B BF16, 30.80M F32 | 10.04M BF16, 5.82K F32 |
| Safetensors weight files | 1.55 TB (245 files) | 20.14 MB (model.safetensors) |
| Architecture / input | HYV4-VL; text, image, video | Same |
| Vocabulary rows / tied embeddings | 120,832 / false | Same |
| Backbone layers / MLP layout | 78 / 1 dense + 77 MoE | 10 / 1 dense + MoE |
| Hidden width / dense MLP width | 6,144 / 18,432 | 8 / 128 |
| Routed experts / top-k / shared experts | 256 / 8 / 1 | 32 / 8 / 1 |
| Expert intermediate size | 2,048 | 128 |
| Q heads; non-RoPE / RoPE / V dimensions | 64; 192 / 64 / 256 | 8; 32 / 64 / 32 |
| Q / KV LoRA rank | 2,048 / 512 | 64 / 512 |
| Indexer heads / dimension / top-k | 32 / 128 / 2,048 | 32 / 128 / 2,048 |
| Indexer layer cadence | full at 0, 1, then every 4th layer | Same |
| Independent Hyper-Connections | 4 streams; gated pre-branches | Same |
| MLA gating / learned sinks / SwiGLU clamp | elementwise / enabled / 10 | Same |
| Vision layers / width / output width | 40 / 1,536 / 6,144 | 4 / 64 / 8 |
| DFly2 draft layers | 5 dense MLA layers, fusion and hidden correction | Same structure |
| Checkpoint precision | BF16; FP32 iHC, attention sinks and router correction bias | Same |
The pinned Transformers hy_v4_vl class stops at the vision tower and language backbone; the ten-layer tiny keeps the source DFly2 drafter in the checkpoint. The DFly2 drafter is not executed by the Transformers example. M-RoPE sections are 12/10/10 as in the source.
| File path | Size |
|---|---|
| model.safetensors | 20.1MB |
Example usage
Transformers (✅ verified)
Hy4's Gated DSA with learned sinks has no optimized Transformers kernel, so the example uses eager attention. hy_v4_vl is not in a released Transformers version; install it with pip install "transformers @ git+https://github.com/huggingface/transformers@439bba079891ecd766900e8ce80ee961b94ef132" first.
def run_transformers(model_id: str):
import numpy as np
import torch
from PIL import Image, ImageDraw
from transformers import AutoModelForImageTextToText, AutoProcessor
from transformers.video_utils import VideoMetadata
model_id = str(model_id)
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(
model_id, dtype=torch.bfloat16, device_map="cuda", attn_implementation="eager"
)
image = Image.new("RGB", (128, 128), "white")
ImageDraw.Draw(image).text((20, 20), "Hello", fill="black")
frames = np.stack(
[
np.asarray(Image.new("RGB", (64, 64), color))
for color in ((220, 30, 30), (30, 220, 30), (30, 30, 220), (220, 220, 30))
]
)
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": image},
{"type": "video", "video": frames},
{"type": "text", "text": "Describe the image and the video."},
],
}
]
inputs = processor.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt",
do_sample_frames=False,
video_metadata=[VideoMetadata(total_num_frames=4, fps=2, frames_indices=[0, 1, 2, 3])],
).to(model.device)
mm = inputs["mm_token_type_ids"]
with torch.no_grad():
logits = model(**inputs).logits
assert torch.isfinite(logits).all()
output = model.generate(**inputs, do_sample=False, max_new_tokens=10)
assert int((mm == 1).sum()) > 0 and int((mm == 2).sum()) > 0
print(processor.decode(output[0, inputs["input_ids"].shape[1] :], skip_special_tokens=True))
if __name__ == "__main__":
run_transformers(model_id="tiny-random/hy4")
SGLang (✅ verified)
Hy4-VL support is in SGLang PR #51672 (git+https://github.com/sgl-project/sglang.git@a0804a2f99719f5666ed2018e5d00a75645de6a8#subdirectory=python), not a released wheel; see the Hy4 cookbook. Install it into a CUDA 13 stack (torch 2.14.1+cu130, flashinfer 0.7.4, sgl-fa3, sgl-flash-mla) and set SGLANG_SKIP_SGL_KERNEL_VERSION_CHECK=1; on an H20 (driver 535) prepend the extracted cuda-compat-13 libcuda.so.1 to LD_LIBRARY_PATH and LIBRARY_PATH.
sglang serve --model-path tiny-random/hy4 --tp 1 \
--dtype bfloat16 --context-length 4096 \
--reasoning-parser auto --tool-call-parser auto \
--served-model-name hy4 --host 0.0.0.0 --port 30000
Send OpenAI chat messages. Text is a plain string; images and videos are image_url / video_url content parts (a local path or base64 data: URI). A video is one URL whose target is a frame container; to reuse the same 4-frame clip the tiny tests use, pass an mp4 or a video file.
from openai import OpenAI
client = OpenAI(base_url="http://localhost:30000/v1", api_key="EMPTY")
# Text + image + video in one user message
messages = [
{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "path/to/image.jpg"}},
{"type": "video_url", "video_url": {"url": "path/to/clip.mp4"}},
{"type": "text", "text": "Describe the image and the video."},
],
}
]
resp = client.chat.completions.create(model="hy4", messages=messages, max_tokens=64)
print(resp.choices[0].message.content)
Creating this repo
- Code: .meta/create_model.py
- Model structure: .meta/model.log
- Environment: .meta/env.json
Change log
- 2026-11-20: Initial tiny Hy4 vision-language checkpoint.
This repo is generated by DeepSeek-V4.1-Flash.
- Downloads last month
- -
Model tree for tiny-random/hy4
Base model
tencent/Hy4