| 44 | } |
| 45 | |
| 46 | bool SanaDiffusion::load() |
| 47 | { |
| 48 | AUTOTIME; |
| 49 | |
| 50 | // 配置后端 |
| 51 | ScheduleConfig config; |
| 52 | BackendConfig backendConfig; |
| 53 | config.type = mBackendType; |
| 54 | backendConfig.memory = BackendConfig::Memory_Low; |
| 55 | |
| 56 | if (config.type == MNN_FORWARD_CPU) |
| 57 | { |
| 58 | config.numThread = 4; |
| 59 | } |
| 60 | else if (config.type == MNN_FORWARD_OPENCL) |
| 61 | { |
| 62 | config.mode = MNN_GPU_MEMORY_BUFFER | MNN_GPU_TUNING_FAST; |
| 63 | } |
| 64 | else if (config.type == MNN_FORWARD_METAL) |
| 65 | { |
| 66 | backendConfig.precision = BackendConfig::Precision_High; |
| 67 | config.numThread = 1; |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | config.numThread = 1; |
| 72 | } |
| 73 | |
| 74 | config.backendConfig = &backendConfig; |
| 75 | |
| 76 | auto exe = ExecutorScope::Current(); |
| 77 | exe->lazyEval = false; |
| 78 | exe->setGlobalExecutorConfig(config.type, backendConfig, config.numThread); |
| 79 | |
| 80 | Module::Config module_config; |
| 81 | module_config.shapeMutable = false; |
| 82 | runtime_manager_.reset(Executor::RuntimeManager::createRuntimeManager(config)); |
| 83 | |
| 84 | // 内存优化配置 |
| 85 | if (mMemoryMode == 0) |
| 86 | { |
| 87 | runtime_manager_->setHint(Interpreter::WINOGRAD_MEMORY_LEVEL, 0); |
| 88 | } |
| 89 | else if (mMemoryMode == 2) |
| 90 | { |
| 91 | runtime_manager_->setHint(Interpreter::WINOGRAD_MEMORY_LEVEL, 1); |
| 92 | } |
| 93 | |
| 94 | if (config.type == MNN_FORWARD_OPENCL) |
| 95 | { |
| 96 | const char *cacheFileName = ".tempcache"; |
| 97 | runtime_manager_->setCache(cacheFileName); |
| 98 | } |
| 99 | |
| 100 | // 加载模型组件 |
| 101 | // Sana架构:LLM特征 -> Connector -> Projector -> DiT Transformer -> VAE Decoder |
| 102 | mModules.resize(5); |
| 103 | { |