Hy4 Vision Encoder and Projector
This repository contains the vision component extracted from Tencent Hy4, revision c10c0de5b6f850703fb0a90e65d1c32b558b9167. It retains every original vit.* tensor, including the patch embedding, 40 transformer blocks, visual merger/projector and image-newline embedding. It does not contain the language model, tokenizer or speculative decoder.
- 649 original BF16 tensors and 1,235,126,784 parameters; source tensor names, values, shapes, and dtypes are preserved.
- Vision hidden size 1536, 16 attention heads, patch size 16, 40 blocks. The 2×2 spatial merger projects to 6144 dimensions.
model.safetensorsSHA-256:3ea4256e1d4fdf0deed37a4147279a74481d14f867fd049b94f3f76c1b773254.
Loading
The source uses the HYV4VL implementation in Transformers. Install the pinned Transformers source revision and load with the provided component wrapper:
pip install 'transformers @ git+https://github.com/huggingface/transformers.git@1097d1570e6208063fa49575bb2b6e756a50c2f6' torch safetensors Pillow
from huggingface_hub import snapshot_download
from PIL import Image
import importlib.util, sys, torch
path = snapshot_download('gatilin/hy4-vision-encoder')
spec = importlib.util.spec_from_file_location('hy4_component', f'{path}/component.py')
component = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = component
spec.loader.exec_module(component)
model = component.load_model(path, dtype=torch.float32, device='cpu')
processor = component.load_processor(path)
inputs = processor(images=Image.open('image.jpg').convert('RGB'), return_tensors='pt')
with torch.inference_mode():
outputs = model(pixel_values=inputs['pixel_values'], grid_thw=inputs['image_grid_thw'])
print(outputs.last_hidden_state.shape, outputs.pooler_output.shape)
last_hidden_state contains patch features and pooler_output contains projected tokens, including the native newline embeddings. This is a standalone visual module, not a complete multimodal assistant or an AutoModel checkpoint.
Provenance
The official ModelScope mirror was used for weight transfer. The providers' declared full-file SHA-256 and sizes matched for all eight source shards. The Hugging Face and mirror safetensors headers were compared byte-for-byte; the selected mirror ranges and the resulting tensor payloads were also compared byte-for-byte. Complete source shards were not downloaded or independently hashed. The mirror branch was master, whose content may change; source shard hashes and the immutable Hugging Face revision are recorded in mirror_comparison.json and extraction.json.
Validation
The validation results and script are included in validation.json and validate_local_reference.py. All 649 tensors strictly loaded; two real COCO128 images passed CPU float32 forward tests and explicit attention agreed with SDPA at layers 0, 19 and 39. The test used the pinned upstream visual source over a local Transformers 5.21.1 runtime, with compatibility aliases for two unused multimodal text outputs and a relaxed tokenizer version check. The full pinned Transformers checkout and installation command were not independently tested. This is a CPU smoke test, not full-model equivalence or downstream accuracy validation.
License
The weights and configuration are subject to the original Tencent Hy License, including its additional commercial terms. The included upstream Transformers source files retain their Apache-2.0 notices; see LICENSE-APACHE-2.0 and native_source/source_manifest.json.