lodestones commited on
Commit
56f6f5e
1 Parent(s): d1a3731

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +30 -13
README.md CHANGED
@@ -13,7 +13,7 @@ license_link: https://ai.google.dev/gemma/terms
13
 
14
  **Model Page**: [Gemma](https://ai.google.dev/gemma/docs)
15
 
16
- This model card corresponds to the 7B base version of the Gemma model. You can also visit the model card of the [2B base model](https://huggingface.co/google/gemma-2b), [7B instruct model](https://huggingface.co/google/gemma-7b-it), and [2B instruct model](https://huggingface.co/google/gemma-2b-it).
17
 
18
  **Resources and Technical Documentation**:
19
 
@@ -59,8 +59,8 @@ You can find fine-tuning notebooks under the [`examples/` directory](https://hug
59
  ```python
60
  from transformers import AutoTokenizer, AutoModelForCausalLM
61
 
62
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b")
63
- model = AutoModelForCausalLM.from_pretrained("google/gemma-7b")
64
 
65
  input_text = "Write me a poem about Machine Learning."
66
  input_ids = tokenizer(input_text, return_tensors="pt")
@@ -69,6 +69,23 @@ outputs = model.generate(**input_ids)
69
  print(tokenizer.decode(outputs[0]))
70
  ```
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  #### Running the model on a single / multi GPU
74
 
@@ -77,8 +94,8 @@ print(tokenizer.decode(outputs[0]))
77
  # pip install accelerate
78
  from transformers import AutoTokenizer, AutoModelForCausalLM
79
 
80
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b")
81
- model = AutoModelForCausalLM.from_pretrained("google/gemma-7b", device_map="auto")
82
 
83
  input_text = "Write me a poem about Machine Learning."
84
  input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
@@ -96,8 +113,8 @@ print(tokenizer.decode(outputs[0]))
96
  # pip install accelerate
97
  from transformers import AutoTokenizer, AutoModelForCausalLM
98
 
99
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b")
100
- model = AutoModelForCausalLM.from_pretrained("google/gemma-7b", device_map="auto", torch_dtype=torch.float16)
101
 
102
  input_text = "Write me a poem about Machine Learning."
103
  input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
@@ -112,8 +129,8 @@ print(tokenizer.decode(outputs[0]))
112
  # pip install accelerate
113
  from transformers import AutoTokenizer, AutoModelForCausalLM
114
 
115
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b")
116
- model = AutoModelForCausalLM.from_pretrained("google/gemma-7b", device_map="auto", torch_dtype=torch.bfloat16)
117
 
118
  input_text = "Write me a poem about Machine Learning."
119
  input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
@@ -132,8 +149,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
132
 
133
  quantization_config = BitsAndBytesConfig(load_in_8bit=True)
134
 
135
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b")
136
- model = AutoModelForCausalLM.from_pretrained("google/gemma-7b", quantization_config=quantization_config)
137
 
138
  input_text = "Write me a poem about Machine Learning."
139
  input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
@@ -150,8 +167,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
150
 
151
  quantization_config = BitsAndBytesConfig(load_in_4bit=True)
152
 
153
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b")
154
- model = AutoModelForCausalLM.from_pretrained("google/gemma-7b", quantization_config=quantization_config)
155
 
156
  input_text = "Write me a poem about Machine Learning."
157
  input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
 
13
 
14
  **Model Page**: [Gemma](https://ai.google.dev/gemma/docs)
15
 
16
+ This model card corresponds to the 2B base version of the Gemma model. You can also visit the model card of the [7B base model](https://huggingface.co/google/gemma-7b), [7B instruct model](https://huggingface.co/google/gemma-7b-it), and [2B instruct model](https://huggingface.co/google/gemma-2b-it).
17
 
18
  **Resources and Technical Documentation**:
19
 
 
59
  ```python
60
  from transformers import AutoTokenizer, AutoModelForCausalLM
61
 
62
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b")
63
+ model = AutoModelForCausalLM.from_pretrained("google/gemma-2b")
64
 
65
  input_text = "Write me a poem about Machine Learning."
66
  input_ids = tokenizer(input_text, return_tensors="pt")
 
69
  print(tokenizer.decode(outputs[0]))
70
  ```
71
 
72
+ #### Running the model using Flax on a single GPU / TPU
73
+
74
+
75
+ ```python
76
+ from transformers import AutoTokenizer, FlaxGemmaForCausalLM
77
+
78
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b")
79
+ model = FlaxGemmaForCausalLM.from_pretrained("google/gemma-2b-flax")
80
+ model.params = jax.tree_map(lambda x: jax.device_put(x, jax.devices()[0]).astype(jnp.float16), flax.params)
81
+
82
+ input_text = "Write me a poem about Machine Learning."
83
+ input_ids = jax.device_put(tokenizer(input_text, return_tensors="jax"), jax.devices()[0])
84
+
85
+ outputs = model.generate(**input_ids)
86
+ print(tokenizer.decode(outputs[0][0]))
87
+ ```
88
+
89
 
90
  #### Running the model on a single / multi GPU
91
 
 
94
  # pip install accelerate
95
  from transformers import AutoTokenizer, AutoModelForCausalLM
96
 
97
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b")
98
+ model = AutoModelForCausalLM.from_pretrained("google/gemma-2b", device_map="auto")
99
 
100
  input_text = "Write me a poem about Machine Learning."
101
  input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
 
113
  # pip install accelerate
114
  from transformers import AutoTokenizer, AutoModelForCausalLM
115
 
116
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b")
117
+ model = AutoModelForCausalLM.from_pretrained("google/gemma-2b", device_map="auto", torch_dtype=torch.float16)
118
 
119
  input_text = "Write me a poem about Machine Learning."
120
  input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
 
129
  # pip install accelerate
130
  from transformers import AutoTokenizer, AutoModelForCausalLM
131
 
132
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b")
133
+ model = AutoModelForCausalLM.from_pretrained("google/gemma-2b", device_map="auto", torch_dtype=torch.bfloat16)
134
 
135
  input_text = "Write me a poem about Machine Learning."
136
  input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
 
149
 
150
  quantization_config = BitsAndBytesConfig(load_in_8bit=True)
151
 
152
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b")
153
+ model = AutoModelForCausalLM.from_pretrained("google/gemma-2b", quantization_config=quantization_config)
154
 
155
  input_text = "Write me a poem about Machine Learning."
156
  input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
 
167
 
168
  quantization_config = BitsAndBytesConfig(load_in_4bit=True)
169
 
170
+ tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b")
171
+ model = AutoModelForCausalLM.from_pretrained("google/gemma-2b", quantization_config=quantization_config)
172
 
173
  input_text = "Write me a poem about Machine Learning."
174
  input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")