Instructions to use tiny-random/hy4-flash with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/hy4-flash with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tiny-random/hy4-flash") 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 AutoModelForSeq2SeqLM model = AutoModelForSeq2SeqLM.from_pretrained("tiny-random/hy4-flash", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/hy4-flash with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/hy4-flash" # 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-flash", "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-flash
- SGLang
How to use tiny-random/hy4-flash 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-flash" \ --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-flash", "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-flash" \ --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-flash", "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-flash with Docker Model Runner:
docker model run hf.co/tiny-random/hy4-flash
This is a randomly initialized tiny model based on tencent/Hy4-flash for testing and debugging.
| Feature | Source | This repo |
|---|---|---|
| Checkpoint tensor elements | 220.24B BF16, 8.73M F32, 483.27K I32 | 13.78M BF16, 144.49K F32, 241.64K I32 |
| Safetensors weight files | 440.52 GB (148 files) | 29.16 MB (model.safetensors) |
| Architecture / input | HYV4-Flash; text, image | Same |
| Vocabulary rows / tied embeddings | 120,832 / false | Same |
| Backbone layers / attention cadence | 42 / 2 indexed + 10x(3 SWA + 1 indexed) | 10 / 2 indexed + 2x(3 SWA + 1 indexed) |
| MLP layout | 1 dense + 41 Latent-MoE | 1 dense + 9 Latent-MoE |
| Hidden width / dense MLP width | 3,072 / 13,824 | 16 / 128 |
| Routed experts / top-k / shared | 512 / 16 / 1 | 8 / 8 / 1 |
| Expert intermediate / latent width | 1,536 / 1,536 | 128 / 128 |
| Q heads; non-RoPE / RoPE / V dims | 32; 192 / 64 / 256 | 8; 32 / 64 / 32 |
| Q / KV LoRA rank | 1,024 / 512 | 64 / 512 |
| Engram memory | 4 layers, 2 n-gram orders, 8 heads/order | 2 layers, 2 orders, 8 heads |
| Compressed indexer | stage-2 coarse recall, ratio 4 | Same cadence |
| SWA window | 512 | 512 |
| Independent Hyper-Connections | 4 streams; gated pre-branches | Same |
| DFly2 draft layers | 5 dense MLA layers + fusion + hidden correction | Same structure |
| Checkpoint precision | BF16 | Same |
hy_v4_flash has no released Transformers model; this repo builds with PR #50903. It adds the Engram n-gram memory (hashed lookups over per-layer tables), a stage-2 compressed indexer beside the DSA indexer, sliding-window attention interleaved 3:1 with sparse attention, and Latent-MoE projections. The source formats Engram lookup_table as a serialized buffer and the Latent-MoE projections as routed_expert_{up,down}_proj (latent->hidden and hidden->latent). Two full SWA cycles are retained.
| File path | Size |
|---|---|
| model.safetensors | 29.2MB |
Example usage
Transformers (✅ verified)
Hy4-flash (hy_v4_flash) is in Transformers PR #50903, not a released version; install it with pip install "transformers[torch,vision] @ git+https://github.com/huggingface/transformers.git@refs/pull/50903/head" first. The Engram memory and the compressed indexer only run with eager attention here.
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-flash")
SGLang (✅ verified)
Hy4-flash support is in SGLang PR #51672 (git+https://github.com/sgl-project/sglang.git@a0804a2f99719f5666ed2018e5d00a75645de6a8#subdirectory=python), not a released wheel; see the Hy4-flash 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-flash --tp 2 \
--dtype bfloat16 --context-length 4096 \
--served-model-name hy4-flash --host 0.0.0.0 --port 30000
Send OpenAI chat messages: a plain text string, or image_url content parts for images.
from openai import OpenAI
client = OpenAI(base_url="http://localhost:30000/v1", api_key="EMPTY")
resp = client.chat.completions.create(
model="hy4-flash",
messages=[
{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "path/to/image.jpg"}},
{"type": "text", "text": "Describe this image."},
],
}
],
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-24: Initial tiny Hy4-flash vision-language checkpoint.
This repo is generated by DeepSeek-V4.1-Flash.
- Downloads last month
- 30
Model tree for tiny-random/hy4-flash
Base model
tencent/Hy4-flash