Views
No views yet
pip install -U transformers, then copy the snippet from the section that is relevant for your usecase.examples/ directory of google/gemma-7b repository. To adapt it to this model, simply change the model-id to yatharth97/yatharth-gemma-7b-it-10k.
In that repository, we provide:torch.bfloat16 as the default dtype. You can use a different precision if necessary.1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4tokenizer = AutoTokenizer.from_pretrained("yatharth97/yatharth-gemma-7b-it-10k")
5model = AutoModelForCausalLM.from_pretrained(
6 "yatharth97/yatharth-gemma-7b-it-10k",
7 torch_dtype=torch.bfloat16
8)
9
10input_text = 'Can you tell me what the Total Debt was in 2023?'
11input_ids = tokenizer(input_text, return_tensors="pt")
12
13outputs = model.generate(**input_ids)
14print(tokenizer.decode(outputs[0]))1# pip install accelerate
2from transformers import AutoTokenizer, AutoModelForCausalLM
3import torch
4
5tokenizer = AutoTokenizer.from_pretrained("yatharth97/yatharth-gemma-7b-it-10k")
6model = AutoModelForCausalLM.from_pretrained(
7 "yatharth97/yatharth-gemma-7b-it-10k",
8 device_map="auto",
9 torch_dtype=torch.bfloat16
10)
11
12input_text = 'Can you tell me what the Total Debt was in 2023?'
13input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
14
15outputs = model.generate(**input_ids)
16print(tokenizer.decode(outputs[0]))bfloat16 precision. You can use float16, which may be faster on certain hardware, indicating the torch_dtype when loading the model. For convenience, the float16 revision of the repo contains a copy of the weights already converted to that precision.float32 if you skip the dtype, but no precision increase will occur (model weights will just be upcasted to float32). See examples below.torch.float161# pip install accelerate
2from transformers import AutoTokenizer, AutoModelForCausalLM
3import torch
4
5tokenizer = AutoTokenizer.from_pretrained("yatharth97/yatharth-gemma-7b-it-10k")
6model = AutoModelForCausalLM.from_pretrained(
7 "yatharth97/yatharth-gemma-7b-it-10k",
8 device_map="auto",
9 torch_dtype=torch.float16,
10 revision="float16",
11)
12
13input_text = 'Can you tell me what the Total Debt was in 2023?'
14input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
15
16outputs = model.generate(**input_ids)
17print(tokenizer.decode(outputs[0]))torch.bfloat161# pip install accelerate
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4tokenizer = AutoTokenizer.from_pretrained("yatharth97/yatharth-gemma-7b-it-10k")
5model = AutoModelForCausalLM.from_pretrained("yatharth97/yatharth-gemma-7b-it-10k", device_map="auto", torch_dtype=torch.bfloat16)
6
7input_text = 'Can you tell me what the Total Debt was in 2023?'
8input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
9
10outputs = model.generate(**input_ids)
11print(tokenizer.decode(outputs[0]))torch.float321# pip install accelerate
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4tokenizer = AutoTokenizer.from_pretrained("yatharth97/yatharth-gemma-7b-it-10k")
5model = AutoModelForCausalLM.from_pretrained(
6 "yatharth97/yatharth-gemma-7b-it-10k",
7 device_map="auto"
8)
9
10input_text = 'Can you tell me what the Total Debt was in 2023?'
11input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
12
13outputs = model.generate(**input_ids)
14print(tokenizer.decode(outputs[0]))bitsandbytes1# pip install bitsandbytes accelerate
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
4quantization_config = BitsAndBytesConfig(load_in_8bit=True)
5
6tokenizer = AutoTokenizer.from_pretrained("yatharth97/yatharth-gemma-7b-it-10k")
7model = AutoModelForCausalLM.from_pretrained("yatharth97/yatharth-gemma-7b-it-10k", quantization_config=quantization_config)
8
9input_text = 'Can you tell me what the Total Debt was in 2023?'
10input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
11
12outputs = model.generate(**input_ids)
13print(tokenizer.decode(outputs[0]))1# pip install bitsandbytes accelerate
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
4quantization_config = BitsAndBytesConfig(load_in_4bit=True)
5
6tokenizer = AutoTokenizer.from_pretrained("yatharth97/yatharth-gemma-7b-it-10k")
7model = AutoModelForCausalLM.from_pretrained("yatharth97/yatharth-gemma-7b-it-10k", quantization_config=quantization_config)
8
9input_text = 'Can you tell me what the Total Debt was in 2023?'
10input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
11
12outputs = model.generate(**input_ids)
13print(tokenizer.decode(outputs[0]))flash-attn in your environment pip install flash-attn1model = AutoModelForCausalLM.from_pretrained(
2 model_id,
3 torch_dtype=torch.float16,
4+ attn_implementation="flash_attention_2"
5).to(0)1from transformers import AutoTokenizer, AutoModelForCausalLM
2import transformers
3import torch
4
5model_id = "yatharth97/yatharth-gemma-7b-it-10k"
6dtype = torch.bfloat16
7
8tokenizer = AutoTokenizer.from_pretrained(model_id)
9model = AutoModelForCausalLM.from_pretrained(
10 model_id,
11 device_map="cuda",
12 torch_dtype=dtype,
13)
14
15chat = [
16 { "role": "user", "content": "Can you tell me what the Total Debt was in 2023?" },
17]
18prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)<bos><start_of_turn>user
Can you tell me what the Total Debt was in 2023?<end_of_turn>
<start_of_turn>model<start_of_turn> delimiter and then the role of the entity
(either user, for content supplied by the user, or model for LLM responses). Turns finish with
the <end_of_turn> token.1inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
2outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
3print(tokenizer.decode(outputs[0]))