Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use weights_only for loading #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions omni_speech/model/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def load_pretrained_model(model_path, model_base, is_lora=False, s2s=False, load
model = model_cls.from_pretrained(model_base, low_cpu_mem_usage=False, config=lora_cfg_pretrained, **kwargs)
print('Loading additional OmniSpeech weights...')
if os.path.exists(os.path.join(model_path, 'non_lora_trainables.bin')):
non_lora_trainables = torch.load(os.path.join(model_path, 'non_lora_trainables.bin'), map_location='cpu')
non_lora_trainables = torch.load(os.path.join(model_path, 'non_lora_trainables.bin'), map_location='cpu', weights_only=True)
non_lora_trainables = {(k[11:] if k.startswith('base_model.') else k): v for k, v in non_lora_trainables.items()}
if any(k.startswith('model.model.') for k in non_lora_trainables):
non_lora_trainables = {(k[6:] if k.startswith('model.') else k): v for k, v in non_lora_trainables.items()}
Expand All @@ -70,7 +70,7 @@ def load_pretrained_model(model_path, model_base, is_lora=False, s2s=False, load
cfg_pretrained = AutoConfig.from_pretrained(model_path)
model = model_cls.from_pretrained(model_base, low_cpu_mem_usage=False, config=cfg_pretrained, **kwargs)

speech_projector_weights = torch.load(os.path.join(model_path, 'speech_projector.bin'), map_location='cpu')
speech_projector_weights = torch.load(os.path.join(model_path, 'speech_projector.bin'), map_location='cpu', weights_only=True)
speech_projector_weights = {k: v.to(torch.float16) for k, v in speech_projector_weights.items()}
model.load_state_dict(speech_projector_weights, strict=False)
model = model.to(device=device)
Expand Down
2 changes: 1 addition & 1 deletion omni_speech/model/omni_speech_arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def initialize_speech_modules(self, model_args, fsdp=None):
p.requires_grad = True

if model_args.pretrain_speech_projector is not None:
pretrain_speech_projector_weights = torch.load(model_args.pretrain_speech_projector, map_location='cpu')
pretrain_speech_projector_weights = torch.load(model_args.pretrain_speech_projector, map_location='cpu', weights_only=True)
def get_w(weights, keyword):
return {k.split(keyword + '.')[1]: v for k, v in weights.items() if keyword in k}

Expand Down