Views
No views yet
transformers version >= 4.25.1.1import torch
2import transformers
3from transformers import AutoTokenizer, AutoModelForCausalLM
4
5MIN_TRANSFORMERS_VERSION = '4.25.1'
6
7# check transformers version
8assert transformers.__version__ >= MIN_TRANSFORMERS_VERSION, f'Please upgrade transformers to version {MIN_TRANSFORMERS_VERSION} or higher.'
9
10# init
11tokenizer = AutoTokenizer.from_pretrained("togethercomputer/RedPajama-INCITE-7B-Base")
12model = AutoModelForCausalLM.from_pretrained("togethercomputer/RedPajama-INCITE-7B-Base", torch_dtype=torch.float16)
13model = model.to('cuda:0')
14# infer
15prompt = "Alan Turing is"
16inputs = tokenizer(prompt, return_tensors='pt').to(model.device)
17input_length = inputs.input_ids.shape[1]
18outputs = model.generate(
19 **inputs, max_new_tokens=128, do_sample=True, temperature=0.7, top_p=0.7, top_k=50, return_dict_in_generate=True
20)
21token = outputs.sequences[0, input_length:]
22output_str = tokenizer.decode(token)
23print(output_str)
24"""
25widely considered to be the father of modern computer science and artificial intelligence. He was a brilliant mathematician and cryptographer, who worked for the British government during World War II. He was instrumental in breaking the German Enigma code, and is credited with helping to shorten the war by two years...
26"""1pip install accelerate
2pip install bitsandbytes1import torch
2import transformers
3from transformers import AutoTokenizer, AutoModelForCausalLM
4
5MIN_TRANSFORMERS_VERSION = '4.25.1'
6
7# check transformers version
8assert transformers.__version__ >= MIN_TRANSFORMERS_VERSION, f'Please upgrade transformers to version {MIN_TRANSFORMERS_VERSION} or higher.'
9
10# init
11tokenizer = AutoTokenizer.from_pretrained("togethercomputer/RedPajama-INCITE-7B-Base")
12model = AutoModelForCausalLM.from_pretrained("togethercomputer/RedPajama-INCITE-7B-Base", device_map='auto', torch_dtype=torch.float16, load_in_8bit=True)
13
14# infer
15prompt = "Alan Turing is"
16inputs = tokenizer(prompt, return_tensors='pt').to(model.device)
17input_length = inputs.input_ids.shape[1]
18outputs = model.generate(
19 **inputs, max_new_tokens=128, do_sample=True, temperature=0.7, top_p=0.7, top_k=50, return_dict_in_generate=True
20)
21token = outputs.sequences[0, input_length:]
22output_str = tokenizer.decode(token)
23print(output_str)
24"""
25a very well-known name in the world of computer science. It is named after the mathematician Alan Turing. He is famous for his work on the Enigma machine, which was used by the Germans during World War II....
26"""```
27
28## CPU Inference
29
30```python
31import torch
32import transformers
33from transformers import AutoTokenizer, AutoModelForCausalLM
34
35MIN_TRANSFORMERS_VERSION = '4.25.1'
36
37# check transformers version
38assert transformers.__version__ >= MIN_TRANSFORMERS_VERSION, f'Please upgrade transformers to version {MIN_TRANSFORMERS_VERSION} or higher.'
39
40# init
41tokenizer = AutoTokenizer.from_pretrained("togethercomputer/RedPajama-INCITE-7B-Base")
42model = AutoModelForCausalLM.from_pretrained("togethercomputer/RedPajama-INCITE-7B-Base", torch_dtype=torch.bfloat16)
43# infer
44prompt = "Alan Turing is"
45inputs = tokenizer(prompt, return_tensors='pt').to(model.device)
46input_length = inputs.input_ids.shape[1]
47outputs = model.generate(
48 **inputs, max_new_tokens=128, do_sample=True, temperature=0.7, top_p=0.7, top_k=50, return_dict_in_generate=True
49)
50token = outputs.sequences[0, input_length:]
51output_str = tokenizer.decode(token)
52print(output_str)
53"""
54one of the most important figures in the history of computing. He is best known for his work on the development of the modern computer and for his code-breaking work during World War II. He was also a brilliant mathematician and philosopher.
55"""LayerNormKernelImpl is not implemented in fp16 for CPU, we use bfloat16 for CPU inference.RedPajama-INCITE-7B-Base is a language model and may not perform well for other use cases outside of its intended scope.
For example, it may not be suitable for use in safety-critical applications or for making decisions that have a significant impact on individuals or society.
It is important to consider the limitations of the model and to only use it for its intended purpose.RedPajama-INCITE-7B-Base is designed for language modeling.
Misuse of the model, such as using it to engage in illegal or unethical activities, is strictly prohibited and goes against the principles of the project.RedPajama-INCITE-7B-Base, like other language models, has limitations that should be taken into consideration.
For example, the model may not always provide accurate or relevant answers, particularly for questions that are complex, ambiguous, or outside of its training data.
We therefore welcome contributions from individuals and organizations, and encourage collaboration towards creating a more robust and inclusive chatbot.