release Image-to-LoRA V2#1495
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for Image-to-LoRA V2 (i2L-v2) models across Z-Image, FLUX.2, and HiDream-O1-Image architectures, adding inference, low-VRAM, training, and validation scripts alongside updated documentation. The review feedback highlights two critical issues: a path mismatch in the HiDream-O1-Image validation script that leads to a FileNotFoundError, and a recurring bug across multiple scripts where adding a scalar to a NumPy array upcasts the datatype, causing PIL's Image.fromarray to crash with a TypeError. Explicitly casting the array to np.uint8 resolves the latter issue.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| device="cuda", | ||
| model_configs=[ModelConfig(model_id="DiffSynth-Studio/HidreamO1-i2L-v2")], | ||
| ) | ||
| template.models[0].load_state_dict(load_state_dict("models/train/HidreamO1-i2L-v2/epoch-1.safetensors")) |
There was a problem hiding this comment.
The output path specified in the training script HidreamO1-i2L-v2.sh is ./models/train/HidreamO1-i2L-v2_full, but the validation script is attempting to load the state dict from models/train/HidreamO1-i2L-v2/epoch-1.safetensors (missing the _full suffix). This mismatch will cause a FileNotFoundError at runtime. Update the path to match the training output directory.
| template.models[0].load_state_dict(load_state_dict("models/train/HidreamO1-i2L-v2/epoch-1.safetensors")) | |
| template.models[0].load_state_dict(load_state_dict("models/train/HidreamO1-i2L-v2_full/epoch-1.safetensors")) |
| prompt="A cat is sitting on a stone", | ||
| seed=42, cfg_scale=4, num_inference_steps=50, | ||
| template_inputs = [{"image": images}], | ||
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], |
There was a problem hiding this comment.
In NumPy, adding a Python integer scalar (like 128) to a uint8 array results in an upcast to int32 or int64 (depending on the platform and NumPy version). When a 3D array with int32 or int64 dtype is passed to Image.fromarray, PIL raises a TypeError: Cannot handle this data type because it only supports uint8 for standard RGB images. Explicitly cast the array to np.uint8 using .astype(np.uint8) to prevent this runtime crash.
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], | |
| negative_template_inputs = [{"image": [Image.fromarray((np.zeros_like(np.array(i)) + 128).astype(np.uint8)) for i in images]}], |
| prompt="A cat is sitting on a stone", | ||
| seed=42, cfg_scale=4, num_inference_steps=50, | ||
| template_inputs = [{"image": images}], | ||
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], |
There was a problem hiding this comment.
In NumPy, adding a Python integer scalar (like 128) to a uint8 array results in an upcast to int32 or int64 (depending on the platform and NumPy version). When a 3D array with int32 or int64 dtype is passed to Image.fromarray, PIL raises a TypeError: Cannot handle this data type because it only supports uint8 for standard RGB images. Explicitly cast the array to np.uint8 using .astype(np.uint8) to prevent this runtime crash.
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], | |
| negative_template_inputs = [{"image": [Image.fromarray((np.zeros_like(np.array(i)) + 128).astype(np.uint8)) for i in images]}], |
| prompt="A cat is sitting on a stone", | ||
| seed=42, cfg_scale=4, num_inference_steps=50, | ||
| template_inputs = [{"image": images}], | ||
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], |
There was a problem hiding this comment.
In NumPy, adding a Python integer scalar (like 128) to a uint8 array results in an upcast to int32 or int64 (depending on the platform and NumPy version). When a 3D array with int32 or int64 dtype is passed to Image.fromarray, PIL raises a TypeError: Cannot handle this data type because it only supports uint8 for standard RGB images. Explicitly cast the array to np.uint8 using .astype(np.uint8) to prevent this runtime crash.
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], | |
| negative_template_inputs = [{"image": [Image.fromarray((np.zeros_like(np.array(i)) + 128).astype(np.uint8)) for i in images]}], |
| prompt="A cat is sitting on a stone", | ||
| seed=0, cfg_scale=4, num_inference_steps=50, | ||
| template_inputs = [{"image": images}], | ||
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], |
There was a problem hiding this comment.
In NumPy, adding a Python integer scalar (like 128) to a uint8 array results in an upcast to int32 or int64 (depending on the platform and NumPy version). When a 3D array with int32 or int64 dtype is passed to Image.fromarray, PIL raises a TypeError: Cannot handle this data type because it only supports uint8 for standard RGB images. Explicitly cast the array to np.uint8 using .astype(np.uint8) to prevent this runtime crash.
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], | |
| negative_template_inputs = [{"image": [Image.fromarray((np.zeros_like(np.array(i)) + 128).astype(np.uint8)) for i in images]}], |
| prompt="A cat is sitting on a stone", | ||
| seed=0, cfg_scale=4, num_inference_steps=50, | ||
| template_inputs = [{"image": images}], | ||
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], |
There was a problem hiding this comment.
In NumPy, adding a Python integer scalar (like 128) to a uint8 array results in an upcast to int32 or int64 (depending on the platform and NumPy version). When a 3D array with int32 or int64 dtype is passed to Image.fromarray, PIL raises a TypeError: Cannot handle this data type because it only supports uint8 for standard RGB images. Explicitly cast the array to np.uint8 using .astype(np.uint8) to prevent this runtime crash.
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], | |
| negative_template_inputs = [{"image": [Image.fromarray((np.zeros_like(np.array(i)) + 128).astype(np.uint8)) for i in images]}], |
| prompt="A cat is sitting on a stone", | ||
| seed=0, cfg_scale=4, num_inference_steps=50, | ||
| template_inputs = [{"image": images}], | ||
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], |
There was a problem hiding this comment.
In NumPy, adding a Python integer scalar (like 128) to a uint8 array results in an upcast to int32 or int64 (depending on the platform and NumPy version). When a 3D array with int32 or int64 dtype is passed to Image.fromarray, PIL raises a TypeError: Cannot handle this data type because it only supports uint8 for standard RGB images. Explicitly cast the array to np.uint8 using .astype(np.uint8) to prevent this runtime crash.
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], | |
| negative_template_inputs = [{"image": [Image.fromarray((np.zeros_like(np.array(i)) + 128).astype(np.uint8)) for i in images]}], |
| prompt="A cat is sitting on a stone", | ||
| seed=0, cfg_scale=4, num_inference_steps=50, | ||
| template_inputs = [{"image": images}], | ||
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], |
There was a problem hiding this comment.
In NumPy, adding a Python integer scalar (like 128) to a uint8 array results in an upcast to int32 or int64 (depending on the platform and NumPy version). When a 3D array with int32 or int64 dtype is passed to Image.fromarray, PIL raises a TypeError: Cannot handle this data type because it only supports uint8 for standard RGB images. Explicitly cast the array to np.uint8 using .astype(np.uint8) to prevent this runtime crash.
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], | |
| negative_template_inputs = [{"image": [Image.fromarray((np.zeros_like(np.array(i)) + 128).astype(np.uint8)) for i in images]}], |
| prompt="A cat is sitting on a stone", | ||
| seed=0, cfg_scale=4, num_inference_steps=50, | ||
| template_inputs = [{"image": images}], | ||
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], |
There was a problem hiding this comment.
In NumPy, adding a Python integer scalar (like 128) to a uint8 array results in an upcast to int32 or int64 (depending on the platform and NumPy version). When a 3D array with int32 or int64 dtype is passed to Image.fromarray, PIL raises a TypeError: Cannot handle this data type because it only supports uint8 for standard RGB images. Explicitly cast the array to np.uint8 using .astype(np.uint8) to prevent this runtime crash.
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], | |
| negative_template_inputs = [{"image": [Image.fromarray((np.zeros_like(np.array(i)) + 128).astype(np.uint8)) for i in images]}], |
| prompt="A cat is sitting on a stone", | ||
| seed=0, cfg_scale=4, num_inference_steps=50, | ||
| template_inputs = [{"image": images}], | ||
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], |
There was a problem hiding this comment.
In NumPy, adding a Python integer scalar (like 128) to a uint8 array results in an upcast to int32 or int64 (depending on the platform and NumPy version). When a 3D array with int32 or int64 dtype is passed to Image.fromarray, PIL raises a TypeError: Cannot handle this data type because it only supports uint8 for standard RGB images. Explicitly cast the array to np.uint8 using .astype(np.uint8) to prevent this runtime crash.
| negative_template_inputs = [{"image": [Image.fromarray(np.zeros_like(np.array(i)) + 128) for i in images]}], | |
| negative_template_inputs = [{"image": [Image.fromarray((np.zeros_like(np.array(i)) + 128).astype(np.uint8)) for i in images]}], |
No description provided.