Add falcon gguf (#33437)
* feat(gguf): add falcon q2 k * fix(gguf): remove useless renaming * feat(gguf): seperate falcon 7b and 40b * feat(gguf): apply fixup * fix(test): error rebase * feat(gguf): add fp16 weight comparison for falcon * feat(gguf): test weight of all layers * test(gguf): add falcon 40b under skip decorator * feat(gguf): quick example for extracting model size
This commit is contained in:
@@ -44,6 +44,9 @@ class GgufIntegrationTests(unittest.TestCase):
|
||||
phi3_model_id = "microsoft/Phi-3-mini-4k-instruct-gguf"
|
||||
bloom_model_id = "afrideva/bloom-560m-GGUF"
|
||||
original_bloom_model_id = "bigscience/bloom-560m"
|
||||
falcon7b_model_id = "xaviviro/falcon-7b-quantized-gguf"
|
||||
falcon40b_model_id = "maddes8cht/tiiuae-falcon-40b-gguf"
|
||||
original_flacon7b_model_id = "tiiuae/falcon-7b"
|
||||
|
||||
# standard quants
|
||||
q4_0_gguf_model_id = "tinyllama-1.1b-chat-v1.0.Q4_0.gguf"
|
||||
@@ -74,6 +77,9 @@ class GgufIntegrationTests(unittest.TestCase):
|
||||
fp16_bloom_model_id = "bloom-560m.fp16.gguf"
|
||||
q8_bloom_model_id = "bloom-560m.q8_0.gguf"
|
||||
f16_tinyllama_model_id = "TinyLlama-1.1B-Chat-v1.0.FP16.gguf"
|
||||
q2_k_falcon7b_model_id = "falcon-7b-q2_k.gguf"
|
||||
fp16_falcon7b_model_id = "falcon-7b-fp16.gguf"
|
||||
q2_k_falcon40b_model_id = "tiiuae-falcon-40b-Q2_K.gguf"
|
||||
|
||||
example_text = "Hello"
|
||||
|
||||
@@ -445,6 +451,58 @@ class GgufIntegrationTests(unittest.TestCase):
|
||||
self.assertTrue(quantized_param.shape == original_param.shape)
|
||||
torch.testing.assert_close(quantized_param, original_param)
|
||||
|
||||
@unittest.skip(reason="Heavy memory")
|
||||
def test_falcon40b_q2_k(self):
|
||||
tokenizer = AutoTokenizer.from_pretrained(self.falcon40b_model_id, gguf_file=self.q2_k_falcon40b_model_id)
|
||||
model = AutoModelForCausalLM.from_pretrained(
|
||||
self.falcon40b_model_id,
|
||||
gguf_file=self.q2_k_falcon40b_model_id,
|
||||
device_map="auto",
|
||||
torch_dtype=torch.float16,
|
||||
)
|
||||
|
||||
text = tokenizer(self.example_text, return_tensors="pt").to(torch_device)
|
||||
out = model.generate(**text, max_new_tokens=10)
|
||||
|
||||
EXPECTED_TEXT = "Hello All,\nI am new to this forum."
|
||||
self.assertEqual(tokenizer.decode(out[0], skip_special_tokens=True), EXPECTED_TEXT)
|
||||
|
||||
def test_falcon7b_q2_k(self):
|
||||
tokenizer = AutoTokenizer.from_pretrained(self.falcon7b_model_id, gguf_file=self.q2_k_falcon7b_model_id)
|
||||
model = AutoModelForCausalLM.from_pretrained(
|
||||
self.falcon7b_model_id,
|
||||
gguf_file=self.q2_k_falcon7b_model_id,
|
||||
device_map="auto",
|
||||
torch_dtype=torch.float16,
|
||||
)
|
||||
|
||||
text = tokenizer(self.example_text, return_tensors="pt").to(torch_device)
|
||||
out = model.generate(**text, max_new_tokens=10)
|
||||
|
||||
EXPECTED_TEXT = "Hello All,\nI am new to this forum."
|
||||
self.assertEqual(tokenizer.decode(out[0], skip_special_tokens=True), EXPECTED_TEXT)
|
||||
|
||||
def test_falcon7b_weights_conversion_fp16(self):
|
||||
quantized_model = AutoModelForCausalLM.from_pretrained(
|
||||
self.falcon7b_model_id,
|
||||
gguf_file=self.fp16_falcon7b_model_id,
|
||||
device_map="auto",
|
||||
torch_dtype=torch.float16,
|
||||
)
|
||||
original_model = AutoModelForCausalLM.from_pretrained(
|
||||
self.original_flacon7b_model_id,
|
||||
device_map="auto",
|
||||
torch_dtype=torch.float16,
|
||||
)
|
||||
|
||||
quantized_state_dict = quantized_model.state_dict()
|
||||
original_state_dict = original_model.state_dict()
|
||||
|
||||
for layer_name, original_params in original_state_dict.items():
|
||||
if layer_name in quantized_state_dict:
|
||||
self.assertTrue(original_params.shape == quantized_state_dict[layer_name].shape)
|
||||
torch.testing.assert_close(original_params, quantized_state_dict[layer_name])
|
||||
|
||||
def test_tokenization_xnli(self):
|
||||
import tqdm
|
||||
from datasets import load_dataset
|
||||
|
||||
Reference in New Issue
Block a user