Feat: Update models.json when pipeline mismatch is detected and corrected

- Add update_model_pipeline_class() function to update model config
- Call function when main model pipeline mismatch is corrected
- Call function when image model pipeline mismatch is corrected
- Ensures future runs use the correct pipeline class automatically
parent b22f0730
......@@ -284,6 +284,33 @@ def save_models_config(models):
print(f"❌ Could not save models config: {e}")
def update_model_pipeline_class(model_name, new_pipeline_class):
"""Update a model's pipeline class in the config file
Called when a pipeline mismatch is detected and corrected.
This ensures future runs use the correct pipeline class.
"""
global MODELS
if model_name not in MODELS:
print(f" ⚠️ Could not update config: model '{model_name}' not found in MODELS")
return False
old_class = MODELS[model_name].get("class", "Unknown")
# Update in-memory config
MODELS[model_name]["class"] = new_pipeline_class
# Save to file
save_models_config(MODELS)
print(f" 📝 Updated model config: {model_name}")
print(f" Old pipeline: {old_class}")
print(f" New pipeline: {new_pipeline_class}")
return True
def validate_hf_model(model_id, hf_token=None, debug=False):
"""Validate if a HuggingFace model exists and get its info
......@@ -3780,6 +3807,8 @@ def main(args):
PipelineClass = CorrectPipelineClass
# Mark as successfully loaded
pipeline_loaded_successfully = True
# Update the models.json file with the correct pipeline class
update_model_pipeline_class(args.model, detected_class)
except Exception as retry_e:
print(f" Retry with {detected_class} also failed: {retry_e}")
# Continue with normal error handling
......@@ -4287,6 +4316,8 @@ def main(args):
print(f" ✅ Successfully loaded image model with {detected_class}")
ImgCls = CorrectImgCls
img_pipeline_loaded_successfully = True
# Update the models.json file with the correct pipeline class
update_model_pipeline_class(args.image_model, detected_class)
except Exception as retry_e:
print(f" ❌ Retry with {detected_class} also failed: {retry_e}")
raise e # Re-raise original error
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment