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

Bug fix to import Llama in OpenLM. #245

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
2 changes: 1 addition & 1 deletion open_lm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def load_model(args, model, different_seed=False):
# loading a bare (model only) checkpoint for fine-tune or evaluation
start_epoch, global_step = 0, 0
pretrained_seed = None
model.load_state_dict(checkpoint)
model.load_state_dict(checkpoint['state_dict'], strict=False)
logging.info(f"=> loaded checkpoint '{args.resume}' (epoch {start_epoch})")
return start_epoch, global_step, pretrained_seed

Expand Down
4 changes: 2 additions & 2 deletions open_lm/positional_embedding/rotary.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, dim_model: int, seq_len: int, *_, **__):
super().__init__()
# Generate and save the inverse frequency buffer (non trainable)
self.dim_model = dim_model
self.register_buffer("inv_freq", torch.zeros(self.dim_model // 2))
self.inv_freq = torch.zeros(self.dim_model // 2)

self._cos_cached = None
self._sin_cached = None
Expand All @@ -71,7 +71,7 @@ def _update_cos_sin_tables(self, seq_len: int = None, device: torch.device = Non
if seq_len > self._seq_len_cached or self._cos_cached.device != device or self._cos_cached.dtype != dtype:
self._seq_len_cached = seq_len
t = torch.arange(seq_len, device=device, dtype=torch.float32)
freqs = torch.einsum("i,j->ij", t, self.inv_freq.to(dtype))
freqs = torch.einsum("i,j->ij", t, self.inv_freq.to(dtype).to(device))
emb = torch.cat((freqs, freqs), dim=-1).to(device)

self._cos_cached = emb.cos()[None, :, None, :].to(dtype)
Expand Down
Loading