Skip to content

Commit 7994b58

Browse files
Wojtek KowalukWojtek Kowaluk
authored andcommitted
clean up duplicated code
1 parent 30939e2 commit 7994b58

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

modules/models.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ def load_model(model_name):
4646
if not any([shared.args.cpu, shared.args.load_in_8bit, shared.args.gptq_bits, shared.args.auto_devices, shared.args.disk, shared.args.gpu_memory is not None, shared.args.cpu_memory is not None, shared.args.deepspeed, shared.args.flexgen, shared.is_RWKV]):
4747
if any(size in shared.model_name.lower() for size in ('13b', '20b', '30b')):
4848
model = AutoModelForCausalLM.from_pretrained(Path(f"models/{shared.model_name}"), device_map='auto', load_in_8bit=True)
49-
if torch.has_mps:
49+
else:
5050
model = AutoModelForCausalLM.from_pretrained(
51-
Path(f"models/{shared.model_name}"),low_cpu_mem_usage=True,
52-
torch_dtype=torch.bfloat16 if shared.args.bf16 else torch.float16
51+
Path(f"models/{shared.model_name}"),
52+
low_cpu_mem_usage=True, torch_dtype=torch.bfloat16 if shared.args.bf16 else torch.float16
5353
)
54-
device = torch.device('mps')
55-
model = model.to(device)
56-
else:
57-
model = AutoModelForCausalLM.from_pretrained(Path(f"models/{shared.model_name}"), low_cpu_mem_usage=True, torch_dtype=torch.bfloat16 if shared.args.bf16 else torch.float16).cuda()
54+
if torch.has_mps:
55+
device = torch.device('mps')
56+
model = model.to(device)
57+
else:
58+
model = model.cuda()
59+
5860

5961
# FlexGen
6062
elif shared.args.flexgen:

0 commit comments

Comments
 (0)