stable-diffusion.cpp/docs/dgl-builtins.md
Wagner Bruna 2c678bcfe9
feat: support for MOSS-Image edit LoRAs (#2203)
Co-authored-by: leejet <leejet714@gmail.com>
2026-11-23 01:05:20 +08:00

26 KiB

Built-in DGL functions

Optional parameters are marked with ?. Default values follow =. See DGL syntax for fn, map and fold.

Function Parameters Returns
add_noise predict: predictor, base: tensor, noise: tensor, sigma: number tensor
animatediff::apply model: denoiser, motion: animatediff denoiser
animatediff::load (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false animatediff
apg positive: predictor, negative: predictor, scale: number, image_only?: predictor, image_scale?: number = 1, schedule?: list<number>, eta?: number = 1, momentum?: number = 0, norm_threshold?: number = 0, norm_threshold_smoothing?: number = 0 predictor
apply_lora model: model, lora: lora, weight?: number = 1.0, mode?: string same type as model
audio::load path: string dict
sample_rate: int
samples: tensor
audio::save path: string, audio: dict, format?: string = "f32" void
audio_latent_shape vae: audio_vae, frames: int, fps: int tensor
audio_vae_decode vae: audio_vae, latent: tensor dict
sample_rate: int
samples: tensor
audio_vae_encode vae: audio_vae, samples: tensor, sample_rate: int tensor
cache mode?: string = "disabled", reuse_threshold?: number, start_percent?: number, end_percent?: number, error_decay_rate?: number, use_relative_threshold?: bool, reset_error_on_compute?: bool, residual_diff_threshold?: number, max_warmup_steps?: int, max_cached_steps?: int, max_continuous_cached_steps?: int, taylorseer_n_derivatives?: int, taylorseer_skip_interval?: int, scm_mask?: string, spectrum_w?: number, spectrum_m?: int, spectrum_lam?: number, spectrum_window_size?: int, spectrum_flex_window?: number, spectrum_warmup_steps?: int, spectrum_stop_percent?: number dict
end_percent: number
error_decay_rate: number
max_cached_steps: int
max_continuous_cached_steps: int
max_warmup_steps: int
mode: string
reset_error_on_compute: bool
residual_diff_threshold: number
reuse_threshold: number
scm_mask: string
spectrum_flex_window: number
spectrum_lam: number
spectrum_m: int
spectrum_stop_percent: number
spectrum_w: number
spectrum_warmup_steps: int
spectrum_window_size: int
start_percent: number
taylorseer_n_derivatives: int
taylorseer_skip_interval: int
use_relative_threshold: bool
cfg positive: predictor, negative: predictor, scale: number, image_only?: predictor, image_scale?: number = 1, schedule?: list<number> predictor
controlnet::apply condition: dict, model: control_net, hint: tensor, strength?: number = 1, start_sigma?: number, end_sigma?: number, type?: string = "none" same type as condition
controls: control_bindings
controlnet::load (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false control_net
denoiser_scalings predict: predictor, sigma: number dict
input_scale: number
output_scale: number
skip_scale: number
detections::box_masks image: tensor, detections: dict list<tensor>
detections::detect detector: detector, image: tensor, input_size?: int = 640, confidence?: number = 0.3, nms?: number = 0.45, max_detections?: int = 100 dict
class_ids: tensor
scores: tensor
xyxy: tensor
detections::filter image: tensor, detections: dict, top_k?: int = 0, top_k_by?: string = "area", min_area_ratio?: number = 0, max_area_ratio?: number = 1, sort_by?: string = "none" dict
class_ids: tensor
scores: tensor
xyxy: tensor
detections::to_regions image: tensor, detections: dict dict
boxes: tensor
height: int
width: int
dit_to_vae_latents vae: vae, latent: tensor tensor
encode_audio encoder: audio_encoder, samples: tensor, sample_rate: int tensor
encode_prompt encoder: text_encoder, text: string, width?: int = 512, height?: int = 512, clip_skip?: int = -1, system?: string, media?: list<any>, image_bindings?: dict, raw?: bool = false dict
concat: tensor
crossattn: tensor
extra_crossattn: list<tensor>
image_embed_indices: list<tensor>
image_embeds: list<tensor>
input_ids: tensor
position_ids: tensor
ref_audios: list<tensor>
ref_images: list<tensor>
reference_blocks: list<dict>
reference_blocks.audio: int
reference_blocks.kind: string
reference_blocks.video: int
t5_ids: tensor
t5_weights: tensor
token_types: tensor
vector: tensor
vinput_mask: tensor
encode_vision encoder: vision_encoder, image: tensor, pooled?: bool = false, clip_skip?: int = -2, zero?: bool = false, zero_input?: bool = false tensor
image::canny image: tensor, high_threshold?: number = 0.08, low_threshold?: number = 0.04, weak?: number = 0.5, strong?: number = 1, invert?: bool = false tensor
image::encode image: tensor, format?: string = "png" dict
data: bytes
mime_type: string
image::load path: string tensor
image::load_dir path: string, max_images?: int = 0 list<tensor>
image::save path: string, image: tensor void
image::to_f32 image: tensor, channels?: int = 0 tensor
image::to_u8 pixels: tensor tensor
ip_adapter::apply condition: dict, adapter: ip_adapter, tokens: tensor, strength?: number = 1, start_sigma?: number, end_sigma?: number same type as condition
ip_adapters: ip_adapter_bindings
ip_adapter::load (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false ip_adapter
ip_adapter::project adapter: ip_adapter, embedding: tensor tensor
latent_shape vae: vae, width: int, height: int, batch?: int = 1, frames?: int tensor
list::replace items: list<any>, index: int, value: any list<any>
load_audio_encoder (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false audio_encoder
load_audio_vae (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false, family_from?: string = "" audio_vae
load_detector (resource) path: string, backend?: string = "", params_backend?: string = "" detector
load_dit (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false denoiser
load_latent_upscaler (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false latent_upscaler
load_lora (resource) path: string lora
load_tae (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false, family_from?: string = "", decode_only?: bool = false vae
load_text_encoder (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false, family_from?: string = "", tokenizer?: string = "", vision_path?: string = "", projection_path?: string = "", connectors_path?: string = "", t5_path?: string = "", clip_l_path?: string = "", clip_g_path?: string = "" text_encoder
load_unet (resource) (alias of load_dit) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false denoiser
load_upscaler (resource) path: string, tile_size?: int = 128, backend?: string = "", params_backend?: string = "", direct?: bool = false upscaler
load_vae (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false, family_from?: string = "", vae_format?: string = "auto" vae
load_vision_encoder (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false vision_encoder
ltx::video_positions like: tensor, keyframe_latent_frames: int, keyframe_frame_index: int, keyframe_pixel_frames: int, fps?: int = 24, spatial_scale?: int = 32, temporal_scale?: int = 8, causal?: bool = true tensor
make_rng algorithm?: string = "cuda", seed?: int = 0 rng
make_sigmas predict: predictor, latent: tensor, scheduler?: string = "discrete", steps: int, flow_shift?: number = 0, sequence_length?: int, extra_args?: string = "" tensor
math::add a: number, b: number number
math::ceil value: number int
math::ceil_div numerator: int, denominator: int int
math::div a: number, b: number number
math::floor value: number int
math::min a: int, b: int int
math::mul a: number, b: number number
math::product items: i64 tensor or list<int> int
math::round value: number int
math::sub a: number, b: number number
media::save path: string, media: dict void
photomaker::apply condition: dict, photomaker: photomaker, tokens: tensor, mask: tensor same type as condition
crossattn: tensor
photomaker::encode_images photomaker: photomaker, images: list<tensor>, id_embedding?: tensor tensor
photomaker::encode_prompt encoder: text_encoder, text: string, tokens: tensor, width?: int = 1024, height?: int = 1024, clip_skip?: int = -1 dict
condition: dict
condition.concat: tensor
condition.crossattn: tensor
condition.extra_crossattn: list<tensor>
condition.image_embed_indices: list<tensor>
condition.image_embeds: list<tensor>
condition.input_ids: tensor
condition.position_ids: tensor
condition.ref_audios: list<tensor>
condition.ref_images: list<tensor>
condition.reference_blocks: list<dict>
condition.reference_blocks.audio: int
condition.reference_blocks.kind: string
condition.reference_blocks.video: int
condition.t5_ids: tensor
condition.t5_weights: tensor
condition.token_types: tensor
condition.vector: tensor
condition.vinput_mask: tensor
mask: tensor
plain: dict
plain.concat: tensor
plain.crossattn: tensor
plain.extra_crossattn: list<tensor>
plain.image_embed_indices: list<tensor>
plain.image_embeds: list<tensor>
plain.input_ids: tensor
plain.position_ids: tensor
plain.ref_audios: list<tensor>
plain.ref_images: list<tensor>
plain.reference_blocks: list<dict>
plain.reference_blocks.audio: int
plain.reference_blocks.kind: string
plain.reference_blocks.video: int
plain.t5_ids: tensor
plain.t5_weights: tensor
plain.token_types: tensor
plain.vector: tensor
plain.vinput_mask: tensor
photomaker::load (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false photomaker
predictor model: denoiser, condition: dict, prediction?: string = "auto", concat?: tensor, ref_latents?: list<tensor>, ref_audios?: list<tensor>, reference_blocks?: list<dict>, keyframe_indices?: list<int>, ref_index_mode?: string = "fixed", force_ref_timestep_zero?: bool = false, ref_rope_anchor?: string = "default", guidance?: number = 3.5, skip_layers?: list<int>, vace_context?: tensor, vace_strength?: number = 1, audio_embedding?: tensor, video_positions?: tensor, audio_length?: int = 0, fps?: number = 24, video_sigma_shift?: number = 12, audio_sigma_shift?: number = 3, circular_x?: bool = false, circular_y?: bool = false, transform?: fn, transform_args?: dict predictor
preview decoder?: vae, circular_x?: bool = false, circular_y?: bool = false sampling_observer
pulid::apply condition: dict, pulid: pulid, embedding: tensor, strength?: number = 1, start_sigma?: number, end_sigma?: number same type as condition
pulid: pulid_bindings
pulid::load (resource) path: string, family?: string = "auto", wtype?: string = "auto", conv_scale?: number = 0, linear_scale?: number = 0, attn_scale?: number = 0, backend?: string = "", params_backend?: string = "", split_mode?: string = "", model_args?: string = "", tensor_type_rules?: string = "", flash_attn_mode?: string = "auto", conv_direct_mode?: string = "auto", sage_attn?: bool = false pulid
pulid::load_embedding path: string tensor
regions::crop image: tensor, regions: dict list<tensor>
regions::from_boxes width: int, height: int, boxes: any dict
boxes: tensor
height: int
width: int
regions::paste background: tensor, foregrounds: list<tensor>, regions: dict tensor
regions::plan_mask_crops masks: list<tensor>, aspect?: i64 tensor or list<int> = [1, 1], padding?: int = 32, only_masked?: bool = true list<dict>
box: tensor
index: int
mask: tensor
relayvsr::decode flash: vae, latent: tensor, frames: tensor, keyframe_indices: tensor, detail?: number = 1 tensor
relayvsr::latent_shape dit: denoiser, keyframes: tensor tensor
relayvsr::positive_embedding dit: denoiser tensor
sample start: tensor, sigmas: tensor, predict: predictor, rng: rng, method?: string = "euler", eta?: number = 1, base?: tensor, denoise_mask?: tensor, mask_input?: bool = false, extra_args?: string = "", finish?: bool, cache?: dict, observer?: sampling_observer tensor
seedvr2::positive_embedding dit: denoiser tensor
sefi::make_sigmas steps: int, alpha?: number = 1, delta?: number = 0.1 dict
semantic_sigmas: tensor
sigmas: tensor
sefi::sample start: tensor, sigmas: tensor, semantic_sigmas: tensor, predict: predictor, rng: rng, method?: string = "euler", eta?: number = 1, base?: tensor, denoise_mask?: tensor, mask_input?: bool = false, extra_args?: string = "", finish?: bool, cache?: dict, observer?: sampling_observer tensor
slg base: predictor, positive: predictor, skipped: predictor, scale: number, start_sigma?: number, end_sigma?: number, start_step_fraction?: number, stop_step_fraction?: number predictor
switch_predictor before: predictor, after: predictor, after_steps: int predictor
t_to_sigma predict: predictor, t: number, flow_shift?: number = 0, latent?: tensor, sequence_length?: int number
tensor::add a: any, b: any tensor
tensor::affine input: tensor, scale?: number = 1, offset?: number = 0 tensor
tensor::arange start: int, end: int, step?: int = 1 tensor
tensor::broadcast_to input: tensor, shape: i64 tensor or list<int> tensor
tensor::cast input: tensor, dtype: string tensor
tensor::clamp input: tensor, min: number, max: number tensor
tensor::concat items: list<tensor>, axis: int tensor
tensor::count_nonzero input: tensor int
tensor::crop input: tensor, axes: i64 tensor or list<int>, start: i64 tensor or list<int>, size: i64 tensor or list<int> tensor
tensor::div a: any, b: any tensor
tensor::full shape: i64 tensor or list<int>, value: number, dtype?: string = "f32" tensor
tensor::gaussian_blur input: tensor, sigma: number, radius: int, axes?: i64 tensor or list<int>, precision?: string = "auto" tensor
tensor::grayscale input: tensor, axis?: int = 0 tensor
tensor::index input: tensor, indices: list<dict> any
tensor::index_fill input: tensor, axis: int, indices: i64 tensor or list<int>, value: number tensor
tensor::index_select input: tensor, axis: int, indices: i64 tensor or list<int> tensor
tensor::interpolate input: tensor, size: i64 tensor or list<int>, axes?: i64 tensor or list<int>, mode?: string = "bilinear", antialias?: bool = false tensor
tensor::lerp a: any, b: any, weight: any tensor
tensor::literal dtype: string, shape: i64 tensor or list<int>, data: string tensor
tensor::load path: string tensor
tensor::max_pool2d input: tensor, kernel: i64 tensor or list<int>, axes?: i64 tensor or list<int>, stride?: i64 tensor or list<int>, padding_before?: i64 tensor or list<int>, padding_after?: i64 tensor or list<int>, pad_value?: number tensor
tensor::maximum a: tensor, b: tensor tensor
tensor::min_pool2d input: tensor, kernel: i64 tensor or list<int>, axes?: i64 tensor or list<int>, stride?: i64 tensor or list<int>, padding_before?: i64 tensor or list<int>, padding_after?: i64 tensor or list<int>, pad_value?: number tensor
tensor::mul a: any, b: any tensor
tensor::numel input: tensor int
tensor::pad input: tensor, pad: i64 tensor or list<int>, mode?: string = "constant", value?: number = 0 tensor
tensor::permute input: tensor, axes: i64 tensor or list<int> tensor
tensor::randn_like like: tensor, rng: rng tensor
tensor::replace_slice input: tensor, value: tensor, axis: int, start: int tensor
tensor::reshape input: tensor, shape: i64 tensor or list<int> tensor
tensor::save path: string, tensor: tensor void
tensor::shape input: tensor tensor
tensor::threshold input: tensor, threshold: number, low?: number = 0, high?: number = 1 tensor
tensor::to_list input: tensor, element?: string = "auto" list<any>
tensor::translate input: tensor, axes: i64 tensor or list<int>, offset: i64 tensor or list<int>, value?: number = 0 tensor
tensor::unsqueeze input: tensor, axis: int tensor
tensor::vector values: list<number>, dtype?: string = "f32" tensor
tensor::zeros shape: i64 tensor or list<int>, dtype?: string = "f32" tensor
tensor::zeros_like like: tensor tensor
tiling enabled?: bool = true, temporal_tiling?: bool = false, tile_size_w?: int = 0, tile_size_h?: int = 0, target_overlap?: number = 0.5, rel_size_w?: number = 0, rel_size_h?: number = 0, extra_args?: string = "" dict
enabled: bool
extra_args: string
rel_size_h: number
rel_size_w: number
target_overlap: number
temporal_tiling: bool
tile_size_h: int
tile_size_w: int
unet_to_vae_latents (alias of dit_to_vae_latents) vae: vae, latent: tensor tensor
upscale upscaler: upscaler, image: tensor, factor?: int tensor
upscale_latent upscaler: latent_upscaler, latent: tensor, width?: int, height?: int tensor
vae_decode vae: vae, latent: tensor, tiling?: dict, circular_x?: bool = false, circular_y?: bool = false, dtype?: string = "u8" tensor
vae_encode vae: vae, pixels: tensor, rng: rng, tiling?: dict, circular_x?: bool = false, circular_y?: bool = false, posterior?: string = "sample" tensor
vae_to_dit_latents vae: vae, latent: tensor tensor
vae_to_unet_latents (alias of vae_to_dit_latents) vae: vae, latent: tensor tensor
video::encode video: dict, audio?: dict, format?: string = "webm" dict
data: bytes
mime_type: string
video::join_windows windows: list<tensor>, overlap?: int = 0 tensor
video::load path: string, max_frames?: int = 0, fps_num?: int = 0, fps_den?: int = 1, audio?: bool = true dict
audio: dict
audio.sample_rate: int
audio.samples: tensor
video: dict
video.fps_den: int
video.fps_num: int
video.frames: tensor
video::save path: string, video: dict, audio?: dict, trim_audio?: bool = false, codec?: string = "auto", quality?: int = 90, audio_format?: string = "f32" void
video::split_windows frames: tensor, size: int, overlap?: int = 0 list<tensor>
wan::s2v_audio_window embedding: tensor, latent_frames: int tensor
zero_out condition: dict, fields?: list<string> same type as condition

Model family IDs

Pass the ID as the component loader's family argument. The default is "auto".

ID Model family
sd1 SD 1.x
sd1_inpaint SD 1.x Inpaint
sd1_pix2pix Instruct-Pix2Pix
sd1_tiny_unet SD 1.x Tiny UNet
sd2 SD 2.x
sd2_inpaint SD 2.x Inpaint
sd2_tiny_unet SD 2.x Tiny UNet
sdxs_512_ds SDXS (512-DS)
sdxs_09 SDXS (09)
sdxl SDXL
sdxl_inpaint SDXL Inpaint
sdxl_pix2pix SDXL Instruct-Pix2Pix
sdxl_vega SDXL (Vega)
sdxl_ssd1b SDXL (SSD1B)
svd SVD
sd3 SD3.x
flux Flux
flux_fill Flux Fill
flux_control Flux Control
flex2 Flex.2
chroma_radiance Chroma Radiance
wan2 Wan 2.x
wan2_2_i2v Wan 2.2 I2V
wan2_2_ti2v Wan 2.2 TI2V
wan2_2_s2v Wan 2.2 S2V
lingbot_video LingBot Video
qwen_image Qwen Image
qwen_image_layered Qwen Image Layered
qwen_image_2_1 Qwen Image 2.1
hunyuan_video Hunyuan Video
anima Anima
flux2 Flux.2
flux2_klein Flux.2 klein
ltxav LTXAV
minimax_h3 MiniMax-H3
hidream_o1 HiDream O1
z_image Z-Image
boogu_image Boogu Image
ovis_image Ovis Image
ernie_image Ernie Image
lens Lens
minit2i MiniT2I
longcat_image Longcat-Image
pid PiD
ideogram4 Ideogram 4
sefi_image SeFi-Image
krea2 Krea2
mage_flow Mage Flow
sensenova_u1_5 SenseNova U1.5
llada_image LLaDA-Image
esrgan ESRGAN
pixart PixArt
ming_image Ming-Image
z_image_l2p Z-Image L2P
iris_3b Iris-3B
flux3_klein Flux.3 Image Klein
moss_image MOSS-Image
fibo2 Fibo-2.0
chroma Chroma
p_h3_image P-H3-Image
minimax_h3_image MiniMax-H3-Image
relayvsr RelayVSR
seedvr2 SeedVR2