Downloads · 30 days
16
7% of all-time downloads
michaelfeil/ct2fast-phi-1
ct2fast-phi-1 is a text generation model from michaelfeil. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as other.
Speedup inference while reducing memory by 2x-4x using int8 inference in C++ on CPU or GPU.
Downloads · 30 days
16
7% of all-time downloads
All-time downloads
225
Public
Repo size
1.4 GB
Likes
0
Public
Click a slice to open those files.
.bin1.4 GB · 100%
From the Hugging Face model README
Speedup inference while reducing memory by 2x-4x using int8 inference in C++ on CPU or GPU.
quantized version of microsoft/phi-1
pip install hf-hub-ctranslate2>=2.12.0 ctranslate2>=3.17.1
# from transformers import AutoTokenizer
model_name = "michaelfeil/ct2fast-phi-1"
from hf_hub_ctranslate2 import GeneratorCT2fromHfHub
model = GeneratorCT2fromHfHub(
# load in int8 on CUDA
model_name_or_path=model_name,
device="cuda",
compute_type="int8_float16",
# tokenizer=AutoTokenizer.from_pretrained("{ORG}/{NAME}")
)
outputs = model.generate(
text=["def fibonnaci(", "User: How are you doing? Bot:"],
max_length=64,
include_prompt_in_result=False
)
print(outputs)
Checkpoint compatible to ctranslate2>=3.22.0 and hf-hub-ctranslate2>=2.12.0
compute_type=int8_float16 for device="cuda"compute_type=int8 for device="cpu"Converted on 2023-11-30 using
TransformersConverter(
"microsoft/phi-1",
activation_scales=None,
copy_files=['vocab.json', 'tokenizer.json', 'generation_config.json', 'README.md', 'special_tokens_map.json', 'merges.txt', 'Research License.docx', 'tokenizer_config.json', 'added_tokens.json', '.gitattributes'],
load_as_float16=True,
revision=None,
low_cpu_mem_usage=True,
trust_remote_code=True,
).convert(
output_dir=str(tmp_dir),
vmap = None,
quantization="int8_float16",
force = True,
)
This is just a quantized version. Licence conditions are intended to be idential to original huggingface repo.
The language model phi-1 is a Transformer with 1.3 billion parameters, specialized for basic Python coding. Its training involved a variety of data sources, including subsets of Python codes from The Stack v1.2, Q&A content from StackOverflow, competition code from code_contests, and synthetic Python textbooks and exercises generated by gpt-3.5-turbo-0301. Even though the model and the datasets are relatively small compared to contemporary Large Language Models (LLMs), phi-1 has demonstrated an impressive accuracy rate exceeding 50% on the simple Python coding benchmark, HumanEval.
Given the nature of the training data, phi-1 is best suited for prompts using the code format:
def print_prime(n):
"""
Print all primes between 1 and n
"""
for num in range(2, n+1):
for i in range(2, num):
if num % i == 0:
break
else:
print(num)
where the model generates the code after the comments. (Note: This is a legitimate and correct use of the else statement in Python loops.)
Notes
When leveraging phi-1, it's paramount to be vigilant. The model, though powerful, can inadvertently introduce security vulnerabilities in the generated code. Examples include, but are not limited to:
Given these potential pitfalls, and others not explicitly mentioned, it's essential to thoroughly review, test, and verify the generated code before deploying it in any application, especially those that are security-sensitive. Always consult with security experts or perform rigorous penetration testing when in doubt.
The model is licensed under the Research License.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
torch.set_default_device("cuda")
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1", trust_remote_code=True)
inputs = tokenizer('''def print_prime(n):
"""
Print all primes between 1 and n
"""''', return_tensors="pt", return_attention_mask=False)
outputs = model.generate(**inputs, max_length=200)
text = tokenizer.batch_decode(outputs)[0]
print(text)
If you need to use the model in a lower precision (e.g., FP16), please wrap the model's forward pass with torch.autocast(), as follows:
with torch.autocast(model.device.type, dtype=torch.float16, enabled=True):
outputs = model.generate(**inputs, max_length=200)
Remark. In the generation function, our model currently does not support beam search (num_beams >1).
Furthermore, in the forward pass of the model, we currently do not support outputting hidden states or attention values, or using custom input embeddings (instead of the model's).
@article{gunasekar2023textbooks,
title={Textbooks Are All You Need},
author={Gunasekar, Suriya and Zhang, Yi and Aneja, Jyoti and Mendes, Caio C{\'e}sar Teodoro and Del Giorno, Allie and Gopi, Sivakanth and Javaheripi, Mojan and Kauffmann, Piero and de Rosa, Gustavo and Saarikivi, Olli and others},
journal={arXiv preprint arXiv:2306.11644},
year={2023}
}