Skip to content

release Image-to-LoRA V2#1495

Open
Artiprocher wants to merge 1 commit into
mainfrom
image-to-lora-v2
Open

release Image-to-LoRA V2#1495
Artiprocher wants to merge 1 commit into
mainfrom
image-to-lora-v2

Conversation

@Artiprocher

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]}],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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]}],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant