Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion unsloth/models/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,9 @@ def unsloth_fast_generate(
*args,
**kwargs,
):
# If the model starts out in training mode, restore training mode after generation
restore_training_mode = self.training

FastLlamaModel.for_inference(self)

dtype = _get_dtype(dtype_from_config(self.config))
Expand Down Expand Up @@ -2043,7 +2046,8 @@ def unsloth_fast_generate(
# accelerate.utils.operations.send_to_device = accelerate_old_send_to_device
# pass

FastLlamaModel.for_training(self)
if restore_training_mode:
FastLlamaModel.for_training(self)

return output

Expand Down
14 changes: 10 additions & 4 deletions unsloth/models/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def from_pretrained(
if model_name.lower().endswith("-bf16"):
load_in_4bit = False
load_in_8bit = False
load_in_fp8 = False
load_in_fp8 = False
load_in_16bit = True

if USE_MODELSCOPE and not os.path.exists(model_name):
Expand Down Expand Up @@ -387,7 +387,7 @@ def from_pretrained(
if model_name.lower().endswith("-bf16"):
load_in_4bit = False
load_in_8bit = False
load_in_fp8 = False
load_in_fp8 = False
load_in_16bit = True

model_config = AutoConfig.from_pretrained(
Expand Down Expand Up @@ -711,10 +711,16 @@ def from_pretrained(
)
load_in_4bit = False
load_in_8bit = False
load_in_fp8 = False
load_in_fp8 = False
load_in_16bit = False

if int(load_in_4bit) + int(load_in_8bit) + int(load_in_16bit) + int(load_in_fp8 != False) >= 2:
if (
int(load_in_4bit)
+ int(load_in_8bit)
+ int(load_in_16bit)
+ int(load_in_fp8 != False)
>= 2
):
raise RuntimeError(
"Unsloth: Can only load in 4bit or 8bit or 16bit, not a combination!\n"
"Also, we by default set `load_in_4bit = True`.\n"
Expand Down