1git clone https://github.com/Tencent-Hunyuan/HY-Embodied
2cd HY-Embodied/
The example script demonstrates both single generation and batch generation capabilities.
1import os
2import torch
3from transformers import AutoModelForImageTextToText, AutoProcessor
4
5# Load model & processor
6MODEL_PATH = "tencent/HY-Embodied-0.5"
7DEVICE = "cuda"
8THINKING_MODE = False
9TEMPERATURE = 0.8
10
11processor = AutoProcessor.from_pretrained(MODEL_PATH)
12
13# Load chat template if available
14chat_template_path = os.path.join(MODEL_PATH, "chat_template.jinja")
15if os.path.exists(chat_template_path):
16 processor.chat_template = open(chat_template_path).read()
17
18model = AutoModelForImageTextToText.from_pretrained(MODEL_PATH, torch_dtype=torch.bfloat16)
19model.to(DEVICE).eval()
20
21# Prepare input messages
22messages = [
23 {
24 "role": "user",
25 "content": [
26 {"type": "image", "image": "./figures/example.jpg"},
27 {"type": "text", "text": "Describe the image in detail."},
28 ],
29 }
30]
31
32# Process and generate
33inputs = processor.apply_chat_template(
34 messages,
35 tokenize=True,
36 add_generation_prompt=True,
37 return_dict=True,
38 return_tensors="pt",
39 enable_thinking=THINKING_MODE,
40).to(model.device)
41
42with torch.no_grad():
43 generated_ids = model.generate(
44 **inputs,
45 max_new_tokens=32768,
46 use_cache=True,
47 temperature=TEMPERATURE,
48 do_sample=TEMPERATURE > 0,
49 )
50
51output_ids = [out[len(inp):] for inp, out in zip(inputs.input_ids, generated_ids)]
52print(processor.batch_decode(output_ids, skip_special_tokens=True)[0])
1import os
2import torch
3from transformers import AutoModelForImageTextToText, AutoProcessor
4
5# Load model & processor
6MODEL_PATH = "tencent/HY-Embodied-0.5"
7DEVICE = "cuda"
8THINKING_MODE = False
9TEMPERATURE = 0.8
10
11processor = AutoProcessor.from_pretrained(MODEL_PATH)
12
13# Load chat template if available
14chat_template_path = os.path.join(MODEL_PATH, "chat_template.jinja")
15if os.path.exists(chat_template_path):
16 processor.chat_template = open(chat_template_path).read()
17
18model = AutoModelForImageTextToText.from_pretrained(MODEL_PATH, torch_dtype=torch.bfloat16)
19model.to(DEVICE).eval()
20
21# Batch Inference (multiple prompts at once)
22messages_batch = [
23 # Sample A: image + text
24 [
25 {
26 "role": "user",
27 "content": [
28 {"type": "image", "image": "./figures/example.jpg"},
29 {"type": "text", "text": "Describe the image in detail."},
30 ],
31 }
32 ],
33 # Sample B: text only
34 [
35 {
36 "role": "user",
37 "content": [
38 {"type": "text", "text": "How to open a fridge?"},
39 ],
40 }
41 ],
42]
43
44# Process each message independently
45all_inputs = []
46for msgs in messages_batch:
47 inp = processor.apply_chat_template(
48 msgs,
49 tokenize=True,
50 add_generation_prompt=True,
51 return_dict=True,
52 return_tensors="pt",
53 enable_thinking=THINKING_MODE,
54 )
55 all_inputs.append(inp)
56
57# Left-pad and batch
58batch = processor.pad(all_inputs, padding=True, padding_side="left").to(model.device)
59
60with torch.no_grad():
61 batch_generated_ids = model.generate(
62 **batch,
63 max_new_tokens=32768,
64 use_cache=True,
65 temperature=TEMPERATURE,
66 do_sample=TEMPERATURE > 0,
67 )
68
69# Decode: strip the padded input portion
70padded_input_len = batch["input_ids"].shape[1]
71for i, msgs in enumerate(messages_batch):
72 out_ids = batch_generated_ids[i][padded_input_len:]
73 print(f"\n--- Sample {i} ---")
74 print(processor.decode(out_ids, skip_special_tokens=True))
If you find it useful for your research and applications, please cite our paper using this BibTeX:
1@article{tencent2026hyembodied05,
2 title={HY-Embodied-0.5: Embodied Foundation Models for Real-World Agents},
3 author={Tencent Robotics X and HY Vision Team},
4 journal={arXiv preprint arXiv:2604.07430},
5 year={2026}
6}
We thank the Hugging Face community for their support and the open-source contributions that made this implementation possible.