refactor: unify model source and weight lifecycle management (#1956)

This commit is contained in:
leejet authored and GitHub committed 2026-09-10 23:53:48 +08:00
1 parent d04e8950c1
commit 6b47fec013
36 files changed
+2548 -1462

No files matched your search

+3 -2
View File
@@ -19,7 +19,7 @@ struct GenerationExtensionInitContext {
const sd_ctx_params_t* params;
SDVersion version;
const String2TensorStorage& tensor_storage_map;
ModelLoader& model_loader;
bool photomaker_source_available;
std::shared_ptr<ModelManager> model_manager;
int n_threads;
std::function<bool(SDBackendModule)> ensure_backend_pair;
@@ -39,7 +39,8 @@ struct GenerationExtensionConditionContext {
struct GenerationExtension {
virtual ~GenerationExtension() = default;
virtual const char* name() const = 0;
virtual ModelComponent component() const = 0;
const char* name() const { return model_component_name(component()); }
virtual bool is_enabled() const {
return false;
}
+4 -10
View File
@@ -109,8 +109,8 @@ struct PhotoMakerExtension : public GenerationExtension {
SDCondition id_condition;
int start_merge_step = -1;
const char* name() const override {
return "photomaker";
ModelComponent component() const override {
return ModelComponent::PhotoMaker;
}
bool is_enabled() const override {
@@ -119,7 +119,7 @@ struct PhotoMakerExtension : public GenerationExtension {
bool init(const GenerationExtensionInitContext& ctx) override {
model_path = SAFE_STR(ctx.params->photo_maker_path);
if (model_path.empty()) {
if (model_path.empty() || !ctx.photomaker_source_available) {
return true;
}
@@ -128,13 +128,7 @@ struct PhotoMakerExtension : public GenerationExtension {
}
PMVersion pm_version = std::strstr(model_path.c_str(), "v2") != nullptr ? PM_VERSION_2 : PM_VERSION_1;
LOG_INFO("loading stacked ID embedding (PHOTOMAKER) model file from '%s'", model_path.c_str());
if (!ctx.model_loader.init_from_file_and_convert_name(model_path, "pmid.")) {
LOG_WARN("loading stacked ID embedding from '%s' failed", model_path.c_str());
return true;
}
pmid_model = std::make_shared<PhotoMakerIDEncoder>(ctx.backend_for(SDBackendModule::PHOTOMAKER),
pmid_model = std::make_shared<PhotoMakerIDEncoder>(ctx.backend_for(SDBackendModule::PHOTOMAKER),
ctx.tensor_storage_map,
"pmid",
ctx.version,
+2 -2
View File
@@ -79,8 +79,8 @@ struct PuLIDExtension : public GenerationExtension {
sd::Tensor<float> id_embedding;
float id_weight = 1.0f;
const char* name() const override {
return "pulid";
ModelComponent component() const override {
return ModelComponent::PuLID;
}
bool is_enabled() const override {