Skip to main content

Flux2Runner

Struct Flux2Runner 

Source
pub struct Flux2Runner { /* private fields */ }
Expand description

FLUX.2 denoiser runner — native CPU or compiled HIR on any Device.

Implementations§

Source§

impl Flux2Runner

Source

pub fn builder() -> Flux2RunnerBuilder

Source

pub fn drop_text_encoder_weights(&self) -> Result<(), Error>

Source

pub fn config(&self) -> &Flux2Config

Source

pub fn device(&self) -> Device

Source

pub fn batch(&self) -> usize

Source

pub fn img_seq(&self) -> usize

Source

pub fn txt_seq(&self) -> usize

Source

pub fn uses_nvfp4(&self) -> bool

Source

pub fn has_text_encoder(&self) -> bool

Source

pub fn has_vae(&self) -> bool

Source

pub fn uses_compiled_denoiser(&self) -> bool

True when denoiser forwards use compiled HIR (Self::device).

Source

pub fn uses_compiled_text_encoder(&self) -> bool

True when text encoding uses compiled HIR on Self::device.

Source

pub fn uses_compiled_vae(&self) -> bool

Source

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

Source

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.

Source

pub fn encode_prompt_native( &self, prompt: &str, ) -> Result<(Vec<f32>, Vec<f32>), Error>

Native CPU text encoder (no IR compile).

Source

pub fn encode_prompt_compiled( &self, prompt: &str, ) -> Result<(Vec<f32>, Vec<f32>), Error>

Encode via compiled text-encoder HIR on Self::device.

Source

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.

Source

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

Source

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.

Source

pub fn has_vae_encoder(&self) -> bool

Source

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.

Source

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.

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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.

Source

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.

Source

pub fn vae_config(&self) -> Option<&Flux2VaeConfig>

Source

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

Source

pub fn decode_to_rgb_native( &self, packed_latents: &[f32], img_ids: &[f32], latent_h: usize, latent_w: usize, ) -> Result<(Vec<u8>, u32, u32), Error>

Native CPU decode (unpack / BN / unpatchify + VAE decoder).

Source

pub fn decode_to_rgb_compiled( &self, packed_latents: &[f32], img_ids: &[f32], latent_h: usize, latent_w: usize, ) -> Result<(Vec<u8>, u32, u32), Error>

Compiled VAE decoder on Self::device (unpack/BN/unpatchify stay on CPU).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V