Build UNSLOTH_MODEL_NAME fresh per load (fixes gpt-oss merged reload)
UNSLOTH_MODEL_NAME was built by prepending its previous os.environ value, so it accumulated load flags across loads and across processes (it is inherited by a save->reload subprocess). After loading a gpt-oss bnb-4bit model, a leftover _load_in_4bit_ stayed in the string, and a subsequent non-4bit load (e.g. reloading a merged_16bit checkpoint) still saw _load_in_4bit_. gpt-oss then kept its BnB router patch (router.linear.weight) while the merged checkpoint stores the stock router.weight, raising 'Unsloth: Critical error since some weights are not initialized'. Rebuild the string from THIS load's model name and flags so each load is self-contained. The model-type tag and load flags are still present, so all UNSLOTH_MODEL_NAME consumers keep working; this only drops stale flags carried over from an unrelated earlier load.
This commit is contained in:
parent
b094bf8590
commit
f7840da285
1 changed files with 8 additions and 1 deletions
|
|
@ -1234,7 +1234,14 @@ class FastModel(FastBaseModel):
|
|||
|
||||
# Save model types and loading method
|
||||
lowered_model_name = model_name.lower()
|
||||
string = os.environ.get("UNSLOTH_MODEL_NAME", "") + model_types_all
|
||||
# Build UNSLOTH_MODEL_NAME freshly from THIS load's model name + flags. Do not
|
||||
# prepend the previous os.environ value: it persists in-process and is inherited
|
||||
# across processes (e.g. a save->reload subprocess), so it accumulates stale load
|
||||
# flags. A leftover "_load_in_4bit_" from an earlier bnb-4bit load would make
|
||||
# gpt-oss wrongly take the BnB router patch (router.linear.weight) when later
|
||||
# reloading a merged 16bit checkpoint (router.weight), raising
|
||||
# "Unsloth: Critical error since some weights are not initialized".
|
||||
string = lowered_model_name + "," + model_types_all
|
||||
if load_in_4bit:
|
||||
string += "_load_in_4bit_"
|
||||
if load_in_8bit:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue