Skip to content

Commit

Permalink
Enable Falcon-7B model test
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinwuTT committed Aug 20, 2024
1 parent a497644 commit a260708
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/models/falcon/test_falcon.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import torch
import pytest

# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoConfig


@pytest.mark.xfail
def test_falcon(record_property):
record_property("model_name", "Falcon")

# Download model from cloud
model_name = "tiiuae/falcon-7b-instruct"

# Falcon hidden_size is 4544, which is too big to fit into layer_norm
config = AutoConfig.from_pretrained(model_name)
config.hidden_size = config.hidden_size // 2

# Pretrained Falcon has no pad_token, add it here
tokenizer = AutoTokenizer.from_pretrained(
model_name, padding_side="left", torch_dtype=torch.bfloat16
)
m = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
tokenizer.pad_token = tokenizer.eos_token

m = AutoModelForCausalLM.from_config(config, torch_dtype=torch.bfloat16)
m.eval()

# Set up sample input
test_input = "This is a sample text from "
inputs = tokenizer(test_input, return_tensors="pt")
inputs = tokenizer(
test_input,
return_tensors="pt",
max_length=32,
padding="max_length",
truncation=True,
)

# Run inference with the original model
with torch.no_grad():
Expand Down

0 comments on commit a260708

Please sign in to comment.