Downloads · 30 days
14
9% of all-time downloads
pixosg/HunyuanImage-3.0-Naruto-Style-Adapter
HunyuanImage-3.0-Naruto-Style-Adapter is a text-to-image model from pixosg. Use it when you need an image from a text prompt. It is set up for adapter-transformers. The card lists the license as other.
Downloads · 30 days
14
9% of all-time downloads
All-time downloads
148
Public
Repo size
46.5 MB
Likes
7
Public
Click a slice to open those files.
.safetensors37.8 MB · 81%
From the Hugging Face model README
You should use in naruto style. at the end of the prompt to trigger the image generation.
We use this repo for training.
This adapter is a Model Derivative of tencent/HunyuanImage-3.0 and is distributed under the Tencent Hunyuan Community License Agreement.
Use of these weights must comply with the Tencent Hunyuan Community License and its territorial and usage restrictions. See the LICENSE and NOTICE files in this repository for details.
This project is not affiliated with, associated with, sponsored by, or endorsed by Tencent.
This model/adapter is provided for non-commercial research and personal use only.
Commercial use (including using the model or its outputs in a paid product, service, or large-scale deployment) is not permitted without obtaining appropriate permissions and verifying all relevant rights.
Users must comply with:
You are solely responsible for ensuring that your use of this adapter and any generated outputs respects third-party IP and applicable laws in your jurisdiction.
This model uses the Naruto BLIP captions dataset.
The dataset authors provide the following citation:
@misc{cervenka2022naruto2,
author = {Cervenka, Eole},
title = {Naruto BLIP captions},
year={2022},
howpublished= {\url{https://huggingface.co/datasets/lambdalabs/naruto-blip-captions/}}
}
in naruto style. (must be at the end)1️⃣ Download and clone the HunyuanImage-3.0 repo
git clone https://github.com/Tencent-Hunyuan/HunyuanImage-3.0.git
cd HunyuanImage-3.0/
# Download base model
hf download tencent/HunyuanImage-3.0 --local-dir ./HunyuanImage-3
2️⃣ Download the adapter
# Download from HuggingFace
hf download pixosg/HunyuanImage-3.0-Naruto-Style-Adapter --local-dir ./hunyuanimage-3-naruto-style-adapter
3️⃣ Load the base model and adapter
from peft import PeftModel
from hunyuan_image_3.hunyuan import HunyuanImage3ForCausalMM
import torch
model_id = "./HunyuanImage-3"
adapter_model_path = "./hunyuanimage-3-naruto-style-adapter"
kwargs = dict(
attn_implementation="sdpa", # Use "flash_attention_2" if FlashAttention is installed
trust_remote_code=True,
dtype=torch.bfloat16,
device_map="auto",
moe_impl="eager",
moe_drop_tokens=True,
)
model = HunyuanImage3ForCausalMM.from_pretrained(model_id, **kwargs)
model.load_tokenizer(model_id)
# Option 1
model.load_adapter(adapter_model_path)
# Option 2
model.get_input_embeddings = lambda: model.model.wte
model.set_input_embeddings = lambda value: setattr(model.model, 'wte', value)
model = PeftModel.from_pretrained(model, adapter_model_path, trust_remote_code=True)
# Generate image
prompt = "Astronaut riding horse on moon in naruto style."
image = model.generate_image(prompt=prompt, stream=True)
image.save("image.png")
4️⃣ Optimized Inference (8-bit Quantization)
While standard BF16 inference typically requires 3x NVIDIA A100 (80GB) GPUs, this 8-bit quantized configuration enables high-quality generation on a single NVIDIA H200 (141GB).
import torch
from transformers import BitsAndBytesConfig
from peft import PeftModel
from hunyuan_image_3.hunyuan import HunyuanImage3ForCausalMM
# ------------------------------------------------------------
# Patch (apply BEFORE model loading)
# Keep attention mask on the same device as the input tensor.
# ------------------------------------------------------------
_orig_prepare = HunyuanImage3ForCausalMM._prepare_attention_mask_for_generation
def _prepare_attention_mask_for_generation_patched(self, inputs_tensor, generation_config, model_kwargs):
attn_mask = _orig_prepare(self, inputs_tensor, generation_config, model_kwargs)
if attn_mask is not None and attn_mask.device != inputs_tensor.device:
attn_mask = attn_mask.to(device=inputs_tensor.device)
return attn_mask
HunyuanImage3ForCausalMM._prepare_attention_mask_for_generation = _prepare_attention_mask_for_generation_patched
# ------------------------------------------------------------
skip_modules = [
"vae",
"vision_model",
"vision_aligner",
"patch_embed",
"timestep_emb",
"time_embed",
"time_embed_2",
"final_layer",
"lm_head",
]
quant_config = BitsAndBytesConfig(
load_in_8bit=True,
llm_int8_threshold=6.0,
llm_int8_skip_modules=skip_modules,
llm_int8_enable_fp32_cpu_offload=True,
)
model_id = "./HunyuanImage-3"
adapter_model_path = "./hunyuanimage-3-naruto-style-adapter"
kwargs = dict(
attn_implementation="sdpa", # Use "flash_attention_2" if available
trust_remote_code=True,
quantization_config=quant_config,
dtype="auto",
device_map="auto",
moe_impl="eager",
moe_drop_tokens=False,
)
model = HunyuanImage3ForCausalMM.from_pretrained(model_id, **kwargs)
model.load_tokenizer(model_id)
# Apply LoRA adapter
model.get_input_embeddings = lambda: model.model.wte
model.set_input_embeddings = lambda value: setattr(model.model, 'wte', value)
model = PeftModel.from_pretrained(model, adapter_model_path, trust_remote_code=True)
# Generate image
prompt = "Astronaut riding horse on moon in naruto style."
image = model.generate_image(prompt=prompt, stream=True)
image.save("image.png")