Views
No views yet
pip install hf-hub-ctranslate2>=2.12.0 ctranslate2>=3.16.01# from transformers import AutoTokenizer
2model_name = "michaelfeil/ct2fast-mpt-7b-instruct"
3
4
5from hf_hub_ctranslate2 import GeneratorCT2fromHfHub
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("{ORG}/{NAME}")
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)compute_type=int8_float16 for device="cuda"compute_type=int8 for device="cpu"ct2-transformers-converter --model mosaicml/mpt-7b-instruct --output_dir ~/tmp-ct2fast-mpt-7b-instruct --force --copy_files tokenizer.json README.md tokenizer_config.json generation_config.json special_tokens_map.json requirements.txt .gitattributes --quantization int8_float16 --trust_remote_codeWhat is a quoll?
A Quoll (pronounced “cool”) is one of Australia’s native carnivorous marsupial mammals, which are also known as macropods or wallabies in other parts around Asia and South America
trust_remote_code=True be passed to the from_pretrained method. This is because we use a custom model architecture that is not yet part of the transformers package.1import transformers
2model = transformers.AutoModelForCausalLM.from_pretrained(
3 'mosaicml/mpt-7b-instruct',
4 trust_remote_code=True
5)trust_remote_code=True be passed to the from_pretrained method.
This is because we use a custom MPT model architecture that is not yet part of the Hugging Face transformers package.
MPT includes options for many training efficiency features such as FlashAttention, ALiBi, QK LayerNorm, and more.cuda:0) with attn_impl='triton' and with bfloat16 precision:1import torch
2import transformers
3
4name = 'mosaicml/mpt-7b-instruct'
5
6config = transformers.AutoConfig.from_pretrained(name, trust_remote_code=True)
7config.attn_config['attn_impl'] = 'triton'
8config.init_device = 'cuda:0' # For fast initialization directly on GPU!
9
10model = transformers.AutoModelForCausalLM.from_pretrained(
11 name,
12 config=config,
13 torch_dtype=torch.bfloat16, # Load model weights in bfloat16
14 trust_remote_code=True
15)1import transformers
2
3name = 'mosaicml/mpt-7b-instruct'
4
5config = transformers.AutoConfig.from_pretrained(name, trust_remote_code=True)
6config.max_seq_len = 4096 # (input + output) tokens can now be up to 4096
7
8model = transformers.AutoModelForCausalLM.from_pretrained(
9 name,
10 config=config,
11 trust_remote_code=True
12)1from transformers import AutoTokenizer
2tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")1from transformers import pipeline
2
3pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, device='cuda:0')
4
5with torch.autocast('cuda', dtype=torch.bfloat16):
6 print(
7 pipe('Here is a recipe for vegan banana bread:\n',
8 max_new_tokens=100,
9 do_sample=True,
10 use_cache=True))1INSTRUCTION_KEY = "### Instruction:"
2RESPONSE_KEY = "### Response:"
3INTRO_BLURB = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
4PROMPT_FOR_GENERATION_FORMAT = """{intro}
5{instruction_key}
6{instruction}
7{response_key}
8""".format(
9 intro=INTRO_BLURB,
10 instruction_key=INSTRUCTION_KEY,
11 instruction="{instruction}",
12 response_key=RESPONSE_KEY,
13)
14
15example = "James decides to run 3 sprints 3 times a week. He runs 60 meters each sprint. How many total meters does he run a week? Explain before answering."
16fmt_ex = PROMPT_FOR_GENERATION_FORMAT.format(instruction=example)fmt_ex is ready to be tokenized and sent through the model.| Hyperparameter | Value |
|---|---|
| n_parameters | 6.7B |
| n_layers | 32 |
| n_heads | 32 |
| d_model | 4096 |
| vocab size | 50432 |
| sequence length | 2048 |
@online{MosaicML2023Introducing,
author = {MosaicML NLP Team},
title = {Introducing MPT-7B: A New Standard for Open-Source, Commercially Usable LLMs},
year = {2023},
url = {www.mosaicml.com/blog/mpt-7b},
note = {Accessed: 2023-03-28}, % change this date
urldate = {2023-03-28} % change this date
}