MCPcopy Create free account
hub / github.com/evilsocket/cake / load

Method load

cake-core/src/models/sd/sd.rs:122–345  ·  view source on GitHub ↗
(context: &mut Context)

Source from the content-addressed store, hash-verified

120 const MODEL_NAME: &'static str = "stable-diffusion";
121
122 async fn load(context: &mut Context) -> Result<Option<Box<Self>>> {
123 let SDArgs {
124 tokenizer,
125 tokenizer_2,
126 sd_version,
127 use_f16,
128 width,
129 height,
130 sliced_attention_size,
131 clip,
132 clip2,
133 vae,
134 unet,
135 use_flash_attention,
136 ..
137 } = &context.args.sd_args;
138
139 let sd_config = match *sd_version {
140 StableDiffusionVersion::V1_5 => {
141 StableDiffusionConfig::v1_5(*sliced_attention_size, *height, *width)
142 }
143 StableDiffusionVersion::V2_1 => {
144 StableDiffusionConfig::v2_1(*sliced_attention_size, *height, *width)
145 }
146 StableDiffusionVersion::Xl => {
147 StableDiffusionConfig::sdxl(*sliced_attention_size, *height, *width)
148 }
149 StableDiffusionVersion::Turbo => {
150 StableDiffusionConfig::sdxl_turbo(*sliced_attention_size, *height, *width)
151 }
152 };
153
154 // Tokenizer
155 info!("Loading the Tokenizer...");
156
157 let tokenizer_file = ModelFile::Tokenizer;
158 let tokenizer = tokenizer_file.get(
159 tokenizer.clone(),
160 *sd_version,
161 *use_f16,
162 context.args.model.clone(),
163 )?;
164 let tokenizer = Tokenizer::from_file(tokenizer).map_err(E::msg)?;
165
166 let pad_id = match &sd_config.clip.pad_with {
167 Some(padding) => *tokenizer.get_vocab(true).get(padding.as_str()).unwrap(),
168 None => *tokenizer.get_vocab(true).get("<|endoftext|>").unwrap(),
169 };
170
171 info!("Tokenizer loaded!");
172
173 // Tokenizer 2
174
175 let mut tokenizer_2_option: Option<Tokenizer> = None;
176 let mut pad_id_2: Option<u32> = None;
177
178 if let StableDiffusionVersion::Xl | StableDiffusionVersion::Turbo = sd_version {
179 info!("Loading the Tokenizer 2...");

Callers

nothing calls this directly

Calls 4

get_node_for_layerMethod · 0.80
getMethod · 0.45
cloneMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected