Loading Models
Diffusers runs diffusion models from Hugging Face. AI Model Hub, which is installed with this package, downloads them. The package declares no model: you write the loading code, and the first load asks for the files.
There are four ways to load a model. Which one to use depends on the files that the model's repository has. The repository stabilityai/stable-diffusion-xl-base-1.0 has the files for the first two.
1. A pipeline repository: FromPretrained
The repository has a model_index.json and one folder per part (unet, text_encoder, vae_decoder, ...), each with a model.onnx or a model.sentis file. This is the layout of diffusers' from_pretrained.
var pipe = await StableDiffusionXLPipeline.FromPretrainedAsync("stabilityai/stable-diffusion-xl-base-1.0");
- Only the files that the pipeline reads download:
model_index.json, the configs and tokenizers, and one model file per part. PyTorch weights,safety_checkerand, for text-to-image,vae_encoderstay on Hugging Face. - AI Model Hub converts each
.onnxfile once. This takes time and memory. A.sentisfile loads as it is, so prefer repositories with.sentisfiles, such as julienkay/FLUX.2-klein-4B-sentis-uint8. When the project has both files of a part, the pipeline loads the.sentisfile. DiffusionPipeline.FromPretrainedAsyncreadsmodel_index.jsonand creates the pipeline that it names.
2. One checkpoint file: FromSingleFile
Most fine-tunes are published as one .safetensors file with the weights of all parts. This is the file of diffusers' from_single_file.
var pipe = await StableDiffusionXLPipeline.FromSingleFileAsync(
"stabilityai/stable-diffusion-xl-base-1.0", "sd_xl_base_1.0.safetensors");
A fine-tune, for example RunDiffusion/Juggernaut-XI-v11:
var pipe = await StableDiffusionXLPipeline.FromSingleFileAsync(
"RunDiffusion/Juggernaut-XI-v11", "Juggernaut-XI-byRunDiffusion.safetensors",
config: "RunDiffusion/Juggernaut-XI-v11");
- The file holds only weights. The configs, the tokenizers and the scheduler come from the diffusers repository
config. The default isstabilityai/stable-diffusion-xl-base-1.0. Only the json and txt files ofconfigdownload. - Nothing is converted. Float16 weights go to the GPU as they are.
- SDXL at 1024×1024 can need more GPU memory than the GPU has, for example on a GPU with 12 GB. Call
pipe.EnableModelCpuOffload()and setpipe.VaeDecoder.UseTiling = true.
3. Single parts: FromSingleFile of a model
Some repositories have one part of a pipeline in a GGUF or .safetensors file, for example a quantized transformer. Load the part and give it to the pipeline. The pipeline repository then does not download that part:
var transformer = Flux2Transformer.FromSingleFile("unsloth/FLUX.2-klein-4B-GGUF", "flux-2-klein-4b-Q8_0.gguf");
var textEncoder = TextEncoder.FromSingleFile("unsloth/Qwen3-4B-GGUF", "Qwen3-4B-Q8_0.gguf");
var pipe = Flux2KleinPipeline.FromPretrained("julienkay/FLUX.2-klein-4B-sentis-uint8",
transformer: transformer, textEncoder: textEncoder);
Quantized weights stay quantized on the GPU.
FLUX.3 [klein] loads all its parts from one repository of such files:
var pipe = Flux3KleinPipeline.FromSingleFile("AtomicChat/FLUX-3-Image-Klein-GGUF",
"FLUX-3-Image-Klein-Q8_0.gguf", "text_encoders/Qwen3-VL-4B-Instruct-Q8_0.gguf", "vae/ae.safetensors");
4. A folder on this device
Give the path of a folder instead of a repository id, as for from_pretrained(path) in diffusers:
var pipe = await DiffusionPipeline.FromPretrainedAsync("D:/Models/my-pipeline");
There is no manifest and no download. AI Model Hub does not convert the ONNX files of a folder, so each part of the folder needs a .sentis file.
The first load
- In the Editor, a load of a model that the project does not have opens the AI Model Hub load prompt. The prompt shows the files that the load reads and their size. Add writes them to the project manifest, with the current commit as
revision, and downloads them. Keep therevisionfor reproducible builds. - An async load (
FromPretrainedAsync,FromSingleFileAsync) waits for the download and then continues. A sync load (FromPretrained,FromSingleFile) fails at once: load again after the download. - To add or download models without code, use Project Settings > Doji > AI > AI Model Hub and Window > AI Model Hub.
- Batch mode and players show no prompt. A load of a model that no manifest declares fails with the manifest entry to add. A load of a declared model that is not ready says what is missing and how to download it, for example with
unity command model_hub_sync --repo <id>. - Builds include the models, or download them at runtime, as the AI Model Hub project settings say.
Review the license of each model on Hugging Face before you use it.