pub struct Flux2Runner { /* private fields */ }Expand description
FLUX.2 denoiser runner — native CPU or compiled HIR on any Device.
Implementations§
Source§impl Flux2Runner
impl Flux2Runner
pub fn builder() -> Flux2RunnerBuilder
pub fn drop_text_encoder_weights(&self) -> Result<(), Error>
pub fn config(&self) -> &Flux2Config
pub fn device(&self) -> Device
pub fn batch(&self) -> usize
pub fn img_seq(&self) -> usize
pub fn txt_seq(&self) -> usize
pub fn uses_nvfp4(&self) -> bool
pub fn has_text_encoder(&self) -> bool
pub fn has_vae(&self) -> bool
Sourcepub fn uses_compiled_denoiser(&self) -> bool
pub fn uses_compiled_denoiser(&self) -> bool
True when denoiser forwards use compiled HIR (Self::device).
Sourcepub fn uses_compiled_text_encoder(&self) -> bool
pub fn uses_compiled_text_encoder(&self) -> bool
True when text encoding uses compiled HIR on Self::device.
pub fn uses_compiled_vae(&self) -> bool
Sourcepub fn warmup_denoiser(
&self,
img_ids: &[f32],
txt_ids: &[f32],
) -> Result<(), Error>
pub fn warmup_denoiser( &self, img_ids: &[f32], txt_ids: &[f32], ) -> Result<(), Error>
Pre-compile the denoiser HIR for the given position ids (RoPE tables are baked in).
Sourcepub fn encode_prompt(&self, prompt: &str) -> Result<(Vec<f32>, Vec<f32>), Error>
pub fn encode_prompt(&self, prompt: &str) -> Result<(Vec<f32>, Vec<f32>), Error>
Encode a text prompt into FLUX.2 encoder_hidden_states and txt_ids.
Uses compiled HIR on Metal / MLX when Self::uses_compiled_text_encoder;
native CPU on CUDA / ROCm / wgpu / Vulkan and CPU otherwise.
Sourcepub fn encode_prompt_native(
&self,
prompt: &str,
) -> Result<(Vec<f32>, Vec<f32>), Error>
pub fn encode_prompt_native( &self, prompt: &str, ) -> Result<(Vec<f32>, Vec<f32>), Error>
Native CPU text encoder (no IR compile).
Sourcepub fn encode_prompt_compiled(
&self,
prompt: &str,
) -> Result<(Vec<f32>, Vec<f32>), Error>
pub fn encode_prompt_compiled( &self, prompt: &str, ) -> Result<(Vec<f32>, Vec<f32>), Error>
Encode via compiled text-encoder HIR on Self::device.
Sourcepub fn forward(
&self,
hidden_states: &[f32],
encoder_hidden_states: &[f32],
timestep: &[f32],
guidance: Option<&[f32]>,
img_ids: &[f32],
txt_ids: &[f32],
) -> Result<Flux2Output, Error>
pub fn forward( &self, hidden_states: &[f32], encoder_hidden_states: &[f32], timestep: &[f32], guidance: Option<&[f32]>, img_ids: &[f32], txt_ids: &[f32], ) -> Result<Flux2Output, Error>
One denoiser forward: latents + text context → noise prediction.
Sourcepub fn vae_encode_rgb(
&self,
rgb: &[f32],
pixel_h: usize,
pixel_w: usize,
) -> Result<Vec<f32>, Error>
pub fn vae_encode_rgb( &self, rgb: &[f32], pixel_h: usize, pixel_w: usize, ) -> Result<Vec<f32>, Error>
VAE encode RGB planar [-1,1] NCHW → latent (compiled on GPU when enabled).
Sourcepub fn encode_rgb_to_packed(
&self,
rgb: &[f32],
pixel_h: usize,
pixel_w: usize,
latent_h: usize,
latent_w: usize,
eff_h: usize,
eff_w: usize,
) -> Result<Vec<f32>, Error>
pub fn encode_rgb_to_packed( &self, rgb: &[f32], pixel_h: usize, pixel_w: usize, latent_h: usize, latent_w: usize, eff_h: usize, eff_w: usize, ) -> Result<Vec<f32>, Error>
Encode planar RGB [-1,1] NCHW to packed transformer latents.
pub fn has_vae_encoder(&self) -> bool
Sourcepub fn prepare_img2img_packed(
&self,
rgb: &[f32],
pixel_h: usize,
pixel_w: usize,
latent_h: usize,
latent_w: usize,
eff_h: usize,
eff_w: usize,
noise: &[f32],
image_strength: f32,
num_inference_steps: usize,
) -> Result<Vec<f32>, Error>
pub fn prepare_img2img_packed( &self, rgb: &[f32], pixel_h: usize, pixel_w: usize, latent_h: usize, latent_w: usize, eff_h: usize, eff_w: usize, noise: &[f32], image_strength: f32, num_inference_steps: usize, ) -> Result<Vec<f32>, Error>
img2img: encode source RGB and blend with noise at the strength-derived sigma.
Sourcepub fn prepare_edit_conditioning(
&self,
images: &[(&[f32], usize, usize)],
eff_h: usize,
eff_w: usize,
latent_h: usize,
latent_w: usize,
) -> Result<Flux2ReferenceConditioning, Error>
pub fn prepare_edit_conditioning( &self, images: &[(&[f32], usize, usize)], eff_h: usize, eff_w: usize, latent_h: usize, latent_w: usize, ) -> Result<Flux2ReferenceConditioning, Error>
Edit mode: encode reference images into concat conditioning tokens.
Sourcepub fn forward_noise(
&self,
hidden_states: &[f32],
encoder_hidden_states: &[f32],
timestep: &[f32],
guidance: Option<&[f32]>,
img_ids: &[f32],
txt_ids: &[f32],
) -> Result<Vec<f32>, Error>
pub fn forward_noise( &self, hidden_states: &[f32], encoder_hidden_states: &[f32], timestep: &[f32], guidance: Option<&[f32]>, img_ids: &[f32], txt_ids: &[f32], ) -> Result<Vec<f32>, Error>
Denoiser noise prediction (compiled on Self::device when not CPU-native).
Sourcepub fn forward_noise_native(
&self,
hidden_states: &[f32],
encoder_hidden_states: &[f32],
timestep: &[f32],
guidance: Option<&[f32]>,
img_ids: &[f32],
txt_ids: &[f32],
) -> Result<Vec<f32>, Error>
pub fn forward_noise_native( &self, hidden_states: &[f32], encoder_hidden_states: &[f32], timestep: &[f32], guidance: Option<&[f32]>, img_ids: &[f32], txt_ids: &[f32], ) -> Result<Vec<f32>, Error>
Native CPU reference forward (no IR compile).
Sourcepub fn forward_noise_dual_native(
&self,
hidden_states: &[f32],
encoder_hidden_states: &[f32],
timestep: &[f32],
timestep_target: &[f32],
guidance: Option<&[f32]>,
img_ids: &[f32],
txt_ids: &[f32],
) -> Result<Vec<f32>, Error>
pub fn forward_noise_dual_native( &self, hidden_states: &[f32], encoder_hidden_states: &[f32], timestep: &[f32], timestep_target: &[f32], guidance: Option<&[f32]>, img_ids: &[f32], txt_ids: &[f32], ) -> Result<Vec<f32>, Error>
Native forward with dual-time embedding (flow-map).
Sourcepub fn forward_noise_compiled(
&self,
hidden_states: &[f32],
encoder_hidden_states: &[f32],
timestep: &[f32],
guidance: Option<&[f32]>,
img_ids: &[f32],
txt_ids: &[f32],
) -> Result<Vec<f32>, Error>
pub fn forward_noise_compiled( &self, hidden_states: &[f32], encoder_hidden_states: &[f32], timestep: &[f32], guidance: Option<&[f32]>, img_ids: &[f32], txt_ids: &[f32], ) -> Result<Vec<f32>, Error>
Compiled HIR denoiser on Self::device (Metal / MLX / CUDA / CPU).
Sourcepub fn forward_noise_dual_compiled(
&self,
hidden_states: &[f32],
encoder_hidden_states: &[f32],
timestep: &[f32],
timestep_target: &[f32],
guidance: Option<&[f32]>,
img_ids: &[f32],
txt_ids: &[f32],
) -> Result<Vec<f32>, Error>
pub fn forward_noise_dual_compiled( &self, hidden_states: &[f32], encoder_hidden_states: &[f32], timestep: &[f32], timestep_target: &[f32], guidance: Option<&[f32]>, img_ids: &[f32], txt_ids: &[f32], ) -> Result<Vec<f32>, Error>
Compiled forward with dual-time temb (flow-map).
Sourcepub fn forward_cfg(
&self,
hidden_states: &[f32],
pos_encoder: &[f32],
neg_encoder: &[f32],
timestep: &[f32],
guidance: Option<&[f32]>,
img_ids: &[f32],
pos_txt_ids: &[f32],
neg_txt_ids: &[f32],
cfg_scale: f32,
) -> Result<Flux2Output, Error>
pub fn forward_cfg( &self, hidden_states: &[f32], pos_encoder: &[f32], neg_encoder: &[f32], timestep: &[f32], guidance: Option<&[f32]>, img_ids: &[f32], pos_txt_ids: &[f32], neg_txt_ids: &[f32], cfg_scale: f32, ) -> Result<Flux2Output, Error>
Classifier-free guidance: positive + negative text, then
neg + cfg_scale * (pos - neg) on the noise prediction.
Sourcepub fn encode_prompt_pair(
&self,
prompt: &str,
negative_prompt: Option<&str>,
) -> Result<(Vec<f32>, Vec<f32>, Option<Vec<f32>>, Option<Vec<f32>>), Error>
pub fn encode_prompt_pair( &self, prompt: &str, negative_prompt: Option<&str>, ) -> Result<(Vec<f32>, Vec<f32>, Option<Vec<f32>>, Option<Vec<f32>>), Error>
Tokenize and encode positive + optional negative prompts.
pub fn vae_config(&self) -> Option<&Flux2VaeConfig>
Sourcepub fn decode_to_rgb(
&self,
packed_latents: &[f32],
img_ids: &[f32],
latent_h: usize,
latent_w: usize,
) -> Result<(Vec<u8>, u32, u32), Error>
pub fn decode_to_rgb( &self, packed_latents: &[f32], img_ids: &[f32], latent_h: usize, latent_w: usize, ) -> Result<(Vec<u8>, u32, u32), Error>
Decode denoised packed latents to interleaved RGB u8 (HWC) and pixel (height, width).
Auto Trait Implementations§
impl !Freeze for Flux2Runner
impl RefUnwindSafe for Flux2Runner
impl Send for Flux2Runner
impl Sync for Flux2Runner
impl Unpin for Flux2Runner
impl UnsafeUnpin for Flux2Runner
impl UnwindSafe for Flux2Runner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more