Instructions to use OzzyGT/idol_custom_blocks with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use OzzyGT/idol_custom_blocks with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("OzzyGT/idol_custom_blocks", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Download before_denoise.py from OzzyGT/idol_custom_blocks: direct link, hf CLI and curl.
- Browser
- Download file 4.2 kB
-
https://huggingface.co/OzzyGT/idol_custom_blocks/resolve/main/before_denoise.py
- Command line
-
hf download hf://OzzyGT/idol_custom_blocks/before_denoise.py
-
curl -L -o before_denoise.py https://huggingface.co/OzzyGT/idol_custom_blocks/resolve/main/before_denoise.py
4.2 kB
| # Copyright 2026 Sperid Labs and The HuggingFace Team. All rights reserved. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| import numpy as np | |
| import torch | |
| from diffusers.modular_pipelines import ( | |
| ModularPipeline, | |
| ModularPipelineBlocks, | |
| PipelineState, | |
| ) | |
| from diffusers.modular_pipelines.modular_pipeline_utils import ( | |
| ComponentSpec, | |
| InputParam, | |
| OutputParam, | |
| ) | |
| from diffusers.utils.torch_utils import randn_tensor | |
| from .components import scheduler_spec, transformer_spec | |
| class IdolSetTimestepsStep(ModularPipelineBlocks): | |
| model_name = "idol" | |
| def description(self) -> str: | |
| return "Sets the shifted flow-matching timesteps (time shift from the scheduler's `shift`, 3.0 by default)." | |
| def expected_components(self) -> list[ComponentSpec]: | |
| return [scheduler_spec()] | |
| def inputs(self) -> list[InputParam]: | |
| return [InputParam.template("num_inference_steps")] | |
| def intermediate_outputs(self) -> list[OutputParam]: | |
| return [ | |
| OutputParam("timesteps", type_hint=torch.Tensor, description="The timesteps of the denoising loop."), | |
| OutputParam("num_inference_steps", type_hint=int, description="The number of denoising steps."), | |
| ] | |
| def __call__(self, components: ModularPipeline, state: PipelineState) -> PipelineState: | |
| block_state = self.get_block_state(state) | |
| device = components._execution_device | |
| sigmas = np.linspace(1.0, 0.0, block_state.num_inference_steps + 1)[:-1] | |
| components.scheduler.set_timesteps(sigmas=sigmas, device=device) | |
| block_state.timesteps = components.scheduler.timesteps | |
| self.set_block_state(state, block_state) | |
| return components, state | |
| class IdolPrepareLatentsStep(ModularPipelineBlocks): | |
| model_name = "idol" | |
| def description(self) -> str: | |
| return "Draws the initial noise for the object latent and the camera latent." | |
| def expected_components(self) -> list[ComponentSpec]: | |
| return [transformer_spec()] | |
| def inputs(self) -> list[InputParam]: | |
| return [ | |
| InputParam( | |
| "image_embeds", | |
| required=True, | |
| type_hint=torch.Tensor, | |
| description="DINOv3 image tokens; sets the batch size.", | |
| ), | |
| InputParam.template("generator"), | |
| ] | |
| def intermediate_outputs(self) -> list[OutputParam]: | |
| return [ | |
| OutputParam("latents", type_hint=torch.Tensor, description="Initial noise of the object latent."), | |
| OutputParam("camera_latents", type_hint=torch.Tensor, description="Initial noise of the camera latent."), | |
| ] | |
| def __call__(self, components: ModularPipeline, state: PipelineState) -> PipelineState: | |
| block_state = self.get_block_state(state) | |
| device = components._execution_device | |
| config = components.transformer.config | |
| batch_size = block_state.image_embeds.shape[0] | |
| # the sampler integrates in float32, like the reference | |
| block_state.latents = randn_tensor( | |
| (batch_size, config.num_latent_tokens, config.in_channels), | |
| generator=block_state.generator, | |
| device=device, | |
| dtype=torch.float32, | |
| ) | |
| block_state.camera_latents = randn_tensor( | |
| (batch_size, 1, config.camera_channels), | |
| generator=block_state.generator, | |
| device=device, | |
| dtype=torch.float32, | |
| ) | |
| self.set_block_state(state, block_state) | |
| return components, state | |