Skip to content
Closed
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
12 changes: 6 additions & 6 deletions examples/models/llama2/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@ def __init__(self, **kwargs):
device = "cpu"
# flake8: noqa: TOR102
checkpoint = torch.load(checkpoint_path, map_location=device)
if kwargs.get("fairseq2", False):
print("Using fairseq2 checkpoint")
checkpoint = convert_to_llama_checkpoint(checkpoint=checkpoint)
if "model" in checkpoint:
# NB: some checkpoint contains a "model" field, which is the actual weights dict
checkpoint = checkpoint["model"]
# get checkpoint dtype
self.dtype = None
if len(checkpoint) > 0:
Expand All @@ -513,12 +519,6 @@ def __init__(self, **kwargs):
print(
f"Mixed dtype model. Dtype of {first.key}: {first.dtype}. Mismatches in the checkpoint: {mismatched_dtypes}"
)
if kwargs.get("fairseq2", False):
print("Using fairseq2 checkpoint")
checkpoint = convert_to_llama_checkpoint(checkpoint=checkpoint)
if "model" in checkpoint:
# NB: some checkpoint contains a "model" field, which is the actual weights dict
checkpoint = checkpoint["model"]
with open(params_path, "r") as f:
params = json.loads(f.read())
max_seq_len = 128
Expand Down