LovnishVerma commited on
Commit
d4b6d9f
1 Parent(s): ebdda2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,24 +1,29 @@
1
  # Install necessary libraries
2
  # !pip install transformers
3
 
4
- from transformers import AutoTokenizer, pipeline
5
  import torch
6
 
7
  # Model and prompt details
8
  model_name = "mlabonne/llama-2-7b-guanaco"
9
  prompt = "What is a large language model?"
10
 
11
- # Load tokenizer and pipeline
12
  tokenizer = AutoTokenizer.from_pretrained(model_name)
13
- text_generation_pipeline = pipeline(
14
- "text-generation",
15
- model=model_name,
16
  torch_dtype=torch.float16,
17
  device_map="auto",
 
18
  )
19
 
20
  # Generate text using the provided prompt
21
- sequences = text_generation_pipeline(
 
 
 
 
 
22
  f'<s>[INST] {prompt} [/INST]',
23
  do_sample=True,
24
  top_k=10,
 
1
  # Install necessary libraries
2
  # !pip install transformers
3
 
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
5
  import torch
6
 
7
  # Model and prompt details
8
  model_name = "mlabonne/llama-2-7b-guanaco"
9
  prompt = "What is a large language model?"
10
 
11
+ # Load tokenizer and model
12
  tokenizer = AutoTokenizer.from_pretrained(model_name)
13
+ model = AutoModelForCausalLM.from_pretrained(
14
+ model_name,
 
15
  torch_dtype=torch.float16,
16
  device_map="auto",
17
+ offload_folder="path/to/offload/folder" # Replace with the path to the offload folder
18
  )
19
 
20
  # Generate text using the provided prompt
21
+ sequences = pipeline(
22
+ "text-generation",
23
+ model=model,
24
+ tokenizer=tokenizer,
25
+ device=0, # Change to the appropriate device index or "cuda" if using GPU
26
+ )(
27
  f'<s>[INST] {prompt} [/INST]',
28
  do_sample=True,
29
  top_k=10,