MCPcopy Create free account
hub / github.com/alibaba/MNN / forwardWithResizeCache

Method forwardWithResizeCache

transformers/diffusion/engine/src/stable_diffusion.cpp:162–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162std::vector<VARP> StableDiffusion::forwardWithResizeCache(int index, const std::vector<VARP>& inputs) {
163 if (index < 0 || index >= mModules.size() || !mModules[index]) {
164 MNN_ERROR("Invalid diffusion module index: %d\n", index);
165 return {};
166 }
167 if (mResizeCachePrepared.size() != mModules.size()) {
168 mResizeCachePrepared.assign(mModules.size(), false);
169 }
170 if (!mResizeCachePrepared[index]) {
171 auto code = mModules[index]->traceOrOptimize(MNN::Interpreter::Session_Resize_Check);
172 if (code != 0) {
173 MNN_PRINT("Resize check is not supported for diffusion module %d, code = %d\n", index, code);
174 } else {
175 mModules[index]->onForward(inputs);
176 code = mModules[index]->traceOrOptimize(MNN::Interpreter::Session_Resize_Fix);
177 if (code != 0) {
178 MNN_PRINT("Resize fix is not supported for diffusion module %d, code = %d\n", index, code);
179 }
180 }
181 mResizeCachePrepared[index] = true;
182 }
183 return mModules[index]->onForward(inputs);
184}
185
186VARP StableDiffusion::text_encoder(const std::vector<int>& ids) {
187 AUTOTIME;

Callers

nothing calls this directly

Calls 3

traceOrOptimizeMethod · 0.80
sizeMethod · 0.45
onForwardMethod · 0.45

Tested by

no test coverage detected