legolasyiu commited on
Commit
6b8d960
·
verified ·
1 Parent(s): fe865a0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +35 -7
README.md CHANGED
@@ -88,13 +88,41 @@ f"""Below is an instruction that describes a task. \
88
  > ```
89
  If you want to use Hugging Face `transformers` to generate text, you can do something like this.
90
  ```py
91
- from transformers import AutoModelForCausalLM, AutoTokenizer
92
- model_id = "EpistemeAI2/Fireball-12B-v1.13a-philosophers"
93
- tokenizer = AutoTokenizer.from_pretrained(model_id)
94
- model = AutoModelForCausalLM.from_pretrained(model_id)
95
- inputs = tokenizer("Hello my name is", return_tensors="pt")
96
- outputs = model.generate(**inputs, max_new_tokens=20)
97
- print(tokenizer.decode(outputs[0], skip_special_tokens=True))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  ```
99
  ## Accelerator mode:
100
  ```py
 
88
  > ```
89
  If you want to use Hugging Face `transformers` to generate text, you can do something like this.
90
  ```py
91
+ # Import necessary libraries
92
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
93
+ import torch
94
+
95
+ # Load the tokenizer
96
+ tokenizer = AutoTokenizer.from_pretrained("EpistemeAI2/Fireball-12B-v1.13a-philosophers")
97
+
98
+
99
+ quantization_config = BitsAndBytesConfig(load_in_4bit=True)
100
+ # Load the model with 4-bit quantization (no need to use .to() later)
101
+ model = AutoModelForCausalLM.from_pretrained(
102
+ "EpistemeAI2/Fireball-12B-v1.13a-philosophers",
103
+ quantization_config=quantization_config,
104
+ device_map="auto" # Automatically map model to devices
105
+ )
106
+
107
+ # Define the input text
108
+ input_text = "What is the difference between inductive and deductive reasoning?,"
109
+
110
+ # Tokenize the input text
111
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
112
+
113
+ # Ensure the input tensors are moved to the correct device
114
+ # Use the first parameter of the model to get the device it's on
115
+ input_ids = input_ids.to(model.device)
116
+
117
+ # Generate text using the model
118
+ output_ids = model.generate(input_ids, max_length=100, num_return_sequences=1)
119
+
120
+ # Decode the generated tokens to text
121
+ output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
122
+
123
+ # Print the output
124
+ print(output_text)
125
+
126
  ```
127
  ## Accelerator mode:
128
  ```py