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

Method load

transformers/diffusion/engine/src/wan_diffusion.cpp:30–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28WanDiffusion::~WanDiffusion() = default;
29
30bool WanDiffusion::load() {
31 AUTOTIME;
32#if !defined(MNN_DIFFUSION_WITH_LLM_TOKENIZER)
33 MNN_ERROR("Wan diffusion requires MNN_BUILD_LLM=ON so diffusion can load tokenizer.mtok\n");
34 return false;
35#endif
36 ScheduleConfig config;
37 BackendConfig backendConfig;
38 config.type = mBackendType;
39 backendConfig.memory = BackendConfig::Memory_Low;
40 backendConfig.precision = BackendConfig::Precision_Low;
41 if (config.type == MNN_FORWARD_CPU) {
42 config.numThread = 4;
43 } else if (config.type == MNN_FORWARD_OPENCL) {
44 config.mode = MNN_GPU_MEMORY_BUFFER | MNN_GPU_TUNING_FAST;
45 } else {
46 config.numThread = 1;
47 }
48 config.backendConfig = &backendConfig;
49
50 auto exe = ExecutorScope::Current();
51 exe->lazyEval = false;
52 exe->setGlobalExecutorConfig(config.type, backendConfig, config.numThread);
53
54 Module::Config moduleConfig;
55 moduleConfig.shapeMutable = false;
56 runtime_manager_.reset(Executor::RuntimeManager::createRuntimeManager(config));
57 if (!runtime_manager_) {
58 MNN_ERROR("Failed to create Wan runtime manager\n");
59 return false;
60 }
61
62 if (config.type == MNN_FORWARD_OPENCL) {
63 runtime_manager_->setCache(".tempcache_wan");
64 }
65 if (mMemoryMode == 0) {
66 runtime_manager_->setHint(Interpreter::WINOGRAD_MEMORY_LEVEL, 0);
67 } else if (mMemoryMode == 2) {
68 runtime_manager_->setHint(Interpreter::WINOGRAD_MEMORY_LEVEL, 1);
69 }
70 if (config.type == MNN_FORWARD_CPU) {
71 runtime_manager_->setHint(Interpreter::DYNAMIC_QUANT_OPTIONS, 2);
72 }
73
74 if (!mTokenizer) {
75 MNN_ERROR("Wan tokenizer is not initialized\n");
76 return false;
77 }
78 if (!mTokenizer->load(mModelPath + "/tokenizer")) {
79 MNN_PRINT("Warning: failed to load tokenizer at %s/tokenizer, trying %s\n", mModelPath.c_str(),
80 mModelPath.c_str());
81 if (!mTokenizer->load(mModelPath)) {
82 MNN_ERROR("Failed to load Wan tokenizer.mtok\n");
83 return false;
84 }
85 }
86
87 mModules.resize(3);

Callers

nothing calls this directly

Calls 8

traceOrOptimizeMethod · 0.80
loadFunction · 0.50
resetMethod · 0.45
setCacheMethod · 0.45
setHintMethod · 0.45
c_strMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected