Model Load Error Fix

The selected_model.tie.weights() is in the wrong position. : def load_model_wrapper(selected_model, loader, autoload=False):
if not autoload:
yield f”The settings for {selected_model} have been updated.nClick on “Load the model” to load it.”
return

if selected_model == ‘None’:
yield “No model selected”
else:
try:
selected_model.tie_weights()
yield f”Loading {selected_model}…”
shared.model_name = selected_model
unload_model()
if selected_model != ”:
shared.model, shared.tokenizer = load_model(shared.model_name, loader)

if shared.model is not None:
yield f”Successfully loaded {selected_model}”
else:
yield f”Failed to load {selected_model}.”
except:
exc = traceback.format_exc()
logger.error(‘Failed to load the model.’)
print(exc)
yield exc

The issue in the code seems to be with the position of the `selected_model.tie_weights()` line. It is currently placed before the model is loaded and assigned to the `shared.model` variable. To fix this, you should move the `selected_model.tie_weights()` line below the `if shared.model is not None` condition. Here’s the updated code:

“`python
def load_model_wrapper(selected_model, loader, autoload=False):
if not autoload:
yield f”The settings for {selected_model} have been updated.nClick on “Load the model” to load it.”
return

if selected_model == ‘None’:
yield “No model selected”
else:
try:
yield f”Loading {selected_model}…”
shared.model_name = selected_model
unload_model()
if selected_model != ”:
shared.model, shared.tokenizer = load_model(shared.model_name, loader)

if shared.model is not None:
selected_model.tie_weights() # Move this line here
yield f”Successfully loaded {selected_model}”
else:
yield f”Failed to load {selected_model}.”
except:
exc = traceback.format_exc()
logger.error(‘Failed to load the model.’)
print(exc)
yield exc
“`

By moving the `selected_model.tie_weights()` line, the model will be loaded before attempting to tie the weights.