WeightMapping
Models & Types · AiDotNet.ModelLoading
Maps weight names between different model formats.
For Beginners
Model weights have names like paths in a file system.
For example, in Stable Diffusion:
- HuggingFace: “model.diffusion_model.input_blocks.0.0.weight”
- Our model: “unet.inputConv.weight”
This class translates between these naming conventions so we can load weights from any source into our models.
How It Works
Different ML frameworks and model releases use different naming conventions. This class provides mappings to translate between them.
Constructors
| Constructor | Summary |
|---|---|
WeightMapping(Dictionary<string, string> mappings) |
Initializes a new instance with custom mappings. |
Properties
| Property | Summary |
|---|---|
IReadOnlyDictionary<string, string> DirectMappings { get; } |
Gets all direct mappings. |
int DirectMappingCount { get; } |
Gets the count of direct mappings. |
int PatternMappingCount { get; } |
Gets the count of pattern mappings. |
Methods
| Method | Summary |
|---|---|
WeightMapping CreateCLIPTextEncoder() |
Creates weight mapping for CLIP text encoder. |
WeightMapping CreateSDXLVAE() |
Creates weight mapping for SDXL VAE. |
WeightMapping CreateStableDiffusionV1UNet() |
Creates weight mapping for Stable Diffusion v1.x UNet. |
WeightMapping CreateStableDiffusionV1VAE() |
Creates weight mapping for Stable Diffusion v1.x VAE. |
string Map(string sourceName) |
Maps a source weight name to the target name. |
void AddMapping(string sourceName, string targetName) |
Adds a direct name mapping. |
void AddPatternMapping(string pattern, string replacement) |
Adds a pattern-based mapping. |