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

load finetunes & local models #2

Open
wants to merge 2 commits into
base: cpu
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
5 changes: 3 additions & 2 deletions mamba_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


parser = argparse.ArgumentParser(description="Text Generation")
parser.add_argument("--model-name", type=str, default="state-spaces/mamba-130m")
parser.add_argument("--model-name", type=str, default="jondurbin/bagel-dpo-2.8b-v0.2")
parser.add_argument("--prompt", type=str, default=None)
parser.add_argument("--promptlen", type=int, default=100)
parser.add_argument("--genlen", type=int, default=100)
Expand All @@ -30,7 +30,8 @@
dtype = torch.float32

print(f"Loading model {args.model_name}")
is_mamba = args.model_name.startswith("state-spaces/mamba-")
is_mamba = args.model_name.startswith("state-spaces/mamba-") or "mamba" in args.model_name.lower() or args.model_name.startswith("jondurbin/bagel-dpo-2.8b-v0.2")
is_mamba = True
if is_mamba:
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
model = MambaLMHeadModel.from_pretrained(args.model_name, device=device, dtype=dtype)
Expand Down
8 changes: 7 additions & 1 deletion mamba_ssm/models/mixer_seq_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import math
from functools import partial
import os
import json

from collections import namedtuple

Expand Down Expand Up @@ -171,7 +172,12 @@ def forward(self, input_ids, position_ids=None, inference_params=None, num_last_

@classmethod
def from_pretrained(cls, pretrained_model_name, device=None, dtype=None, **kwargs):
config_data = load_config_hf(pretrained_model_name)
if os.path.exists(pretrained_model_name):
config = os.path.join(pretrained_model_name, "config.json")
print(f"Loading config: {config}")
config_data = json.load(open(config))
else:
config_data = load_config_hf(pretrained_model_name)
config = MambaConfig(**config_data)
model = cls(config, device=device, dtype=dtype, **kwargs)
model.load_state_dict(load_state_dict_hf(pretrained_model_name, device=device, dtype=dtype))
Expand Down