|
|
@ -40,16 +40,14 @@ def load_model_on_gpus(checkpoint_path: Union[str, os.PathLike], num_gpus: int =
|
|
|
|
if num_gpus < 2 and device_map is None:
|
|
|
|
if num_gpus < 2 and device_map is None:
|
|
|
|
model = AutoModel.from_pretrained(checkpoint_path, trust_remote_code=True, **kwargs).half().cuda()
|
|
|
|
model = AutoModel.from_pretrained(checkpoint_path, trust_remote_code=True, **kwargs).half().cuda()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
from accelerate import load_checkpoint_and_dispatch
|
|
|
|
from accelerate import dispatch_model
|
|
|
|
|
|
|
|
|
|
|
|
model = AutoModel.from_pretrained(checkpoint_path, trust_remote_code=True, **kwargs)
|
|
|
|
model = AutoModel.from_pretrained(checkpoint_path, trust_remote_code=True, **kwargs).half()
|
|
|
|
model = model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if device_map is None:
|
|
|
|
if device_map is None:
|
|
|
|
device_map = auto_configure_device_map(num_gpus)
|
|
|
|
device_map = auto_configure_device_map(num_gpus)
|
|
|
|
|
|
|
|
|
|
|
|
model = load_checkpoint_and_dispatch(
|
|
|
|
model = dispatch_model(model, device_map=device_map)
|
|
|
|
model, checkpoint_path, device_map=device_map, offload_folder="offload", offload_state_dict=True).half()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return model
|
|
|
|
return model
|
|
|
|
|
|
|
|
|
|
|
|