Views
No views yet
pip install hf-hub-ctranslate2>=2.0.8 ctranslate2>=3.14.0ct2-transformers-converter --model openllmplayground/openalpaca_7b_700bt_preview --output_dir /home/michael/tmp-ct2fast-openalpaca_7b_700bt_preview --force --copy_files README.md tokenizer_config.json generation_config.json special_tokens_map.json .gitattributes --quantization int8_float16 --trust_remote_codecompute_type=int8_float16 for device="cuda"compute_type=int8 for device="cpu"1from hf_hub_ctranslate2 import TranslatorCT2fromHfHub, GeneratorCT2fromHfHub
2from transformers import AutoTokenizer
3
4model_name = "michaelfeil/ct2fast-openalpaca_7b_700bt_preview"
5# use either TranslatorCT2fromHfHub or GeneratorCT2fromHfHub here, depending on model.
6model = GeneratorCT2fromHfHub(
7 # load in int8 on CUDA
8 model_name_or_path=model_name,
9 device="cuda",
10 compute_type="int8_float16",
11 # tokenizer=AutoTokenizer.from_pretrained("openllmplayground/openalpaca_7b_700bt_preview")
12)
13outputs = model.generate(
14 text=["def fibonnaci(", "User: How are you doing? Bot:"],
15 max_length=64,
16 include_prompt_in_result=False
17)
18print(outputs)| Batch Size | 64 |
| Learning rate | 2e-5 |
| Epochs | 3 |
| Max length | 1024 |
1import torch
2from transformers import LlamaForCausalLM, LlamaTokenizer
3
4# the previewed version of OpenAlpaca
5model_path = r'openllmplayground/openalpaca_7b_700bt_preview'
6tokenizer = LlamaTokenizer.from_pretrained(model_path)
7model = LlamaForCausalLM.from_pretrained(model_path).cuda()
8tokenizer.bos_token_id, tokenizer.eos_token_id = 1,2 # see https://github.com/openlm-research/open_llama#preview-weights-release-and-usage
9
10# same prompt as provided in https://crfm.stanford.edu/2023/03/13/alpaca.html
11instruction = r'What is an alpaca? How is it different from a llama?'
12'''
13instruction = r'Write an e-mail to congratulate new Standford admits and mention that you are excited about meeting all of them in person.'
14instruction = r'What is the capital of Tanzania?'
15instruction = r'Write a well-thought out abstract for a machine learning paper that proves that 42 is the optimal seed for training neural networks.'
16'''
17
18prompt_no_input = f'Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Response:'
19tokens = tokenizer.encode(prompt_no_input)
20
21tokens = torch.LongTensor(tokens).unsqueeze(0)
22instance = {'input_ids': tokens,
23 'top_k': 50,
24 'top_p': 0.9,
25 'generate_len': 128}
26
27length = len(tokens[0])
28with torch.no_grad():
29 rest = model.generate(
30 input_ids=tokens,
31 max_length=length+instance['generate_len'],
32 use_cache=True,
33 do_sample=True,
34 top_p=instance['top_p'],
35 top_k=instance['top_k']
36 )
37
38output = rest[0][length:]
39string = tokenizer.decode(output, skip_special_tokens=True)
40print(f'[!] Generation results: {string}')@misc{openalpaca,
author = {Yixuan Su and Tian Lan and Deng Cai},
title = {OpenAlpaca: A Fully Open-Source Instruction-Following Model Based On OpenLLaMA},
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/yxuansu/OpenAlpaca}},
}@software{openlm2023openllama,
author = {Xinyang Geng and Hao Liu},
title = {OpenLLaMA: An Open Reproduction of LLaMA},
month = May,
year = 2023,
url = {https://github.com/openlm-research/open_llama}
}@misc{alpaca,
author = {Rohan Taori and Ishaan Gulrajani and Tianyi Zhang and Yann Dubois and Xuechen Li and Carlos Guestrin and Percy Liang and Tatsunori B. Hashimoto },
title = {Stanford Alpaca: An Instruction-following LLaMA model},
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/tatsu-lab/stanford_alpaca}},
}@article{touvron2023llama,
title={Llama: Open and efficient foundation language models},
author={Hugo Touvron and Thibaut Lavril and Gautier Izacard and Xavier Martinet and Marie{-}Anne Lachaux and Timoth{\'{e}}e Lacroix and Baptiste Rozi{\`{e}}re and Naman Goyal and Eric Hambro and Faisal Azhar and Aur{\'{e}}lien Rodriguez and Armand Joulin and Edouard Grave and Guillaume Lample},
journal={arXiv preprint arXiv:2302.13971},
year={2023}
}