Divyasreepat commited on
Commit
778b3b7
·
verified ·
1 Parent(s): 78579d7

Update README.md with new model card content

Browse files
Files changed (1) hide show
  1. README.md +202 -22
README.md CHANGED
@@ -2,25 +2,205 @@
2
  library_name: keras-hub
3
  pipeline_tag: text-generation
4
  ---
5
- This is a [`Llama3` model](https://keras.io/api/keras_hub/models/llama3) uploaded using the KerasHub library and can be used with JAX, TensorFlow, and PyTorch backends.
6
- This model is related to a `CausalLM` task.
7
-
8
- Model config:
9
- * **name:** llama3_backbone
10
- * **trainable:** True
11
- * **vocabulary_size:** 128256
12
- * **num_layers:** 28
13
- * **num_query_heads:** 24
14
- * **hidden_dim:** 3072
15
- * **intermediate_dim:** 8192
16
- * **rope_max_wavelength:** 500000.0
17
- * **rope_position_scaling_factor:** 1
18
- * **rope_frequency_adjustment_factor:** 32
19
- * **rope_low_freq_factor:** 1
20
- * **rope_high_freq_factor:** 4
21
- * **rope_pretraining_sequence_length:** 8192
22
- * **num_key_value_heads:** 8
23
- * **layer_norm_epsilon:** 1e-05
24
- * **dropout:** 0
25
-
26
- This model card has been generated automatically and should be completed by the model author. See [Model Cards documentation](https://huggingface.co/docs/hub/model-cards) for more information.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  library_name: keras-hub
3
  pipeline_tag: text-generation
4
  ---
5
+ ### Model Overview
6
+ Llama 3 is a set of large language models published by Meta. Both pretrained and instruction tuned models are available, and range in size from 7 billion to 70 billion parameters. See the model card below for benchmarks, data sources, and intended use cases.
7
+
8
+ Weights are released under the [Llama 3 Community License](https://ai.meta.com/llama/license/). Keras model code is released under the [Apache 2 License](https://github.com/keras-team/keras-hub/blob/master/LICENSE).
9
+
10
+ ## Links
11
+ * [Llama 3 Quickstart Notebook](https://www.kaggle.com/code/laxmareddypatlolla/llama3-quickstart-notebook)
12
+ * [Llama 3 API Documentation](https://keras.io/api/keras_hub/models/llama3/)
13
+ * [Llama 3 Model Card & Prompt Formats](https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3)
14
+ * [KerasHub Beginner Guide](https://keras.io/guides/keras_hub/getting_started/)
15
+ * [KerasHub Model Publishing Guide](https://keras.io/guides/keras_hub/upload/)
16
+
17
+ ## Installation
18
+
19
+ Keras and KerasHub can be installed with:
20
+
21
+ ```
22
+ pip install -U -q keras-hub
23
+ pip install -U -q keras
24
+ ```
25
+
26
+ Jax, TensorFlow, and Torch come preinstalled in Kaggle Notebooks. For instructions on installing them in another environment see the [Keras Getting Started](https://keras.io/getting_started/) page.
27
+
28
+ ## Presets
29
+
30
+ The following model checkpoints are provided by the Keras team. Full code examples for each are available below.
31
+
32
+ | Preset name | Parameters | Description |
33
+ |-----------------------|------------|---------------|
34
+ |` llama3_8b_en ` | 8.03B | 8 billion parameter, 32-layer, base LLaMA 3 model. |
35
+ |` llama3_8b_en_int8 ` | 8.03B | 8 billion parameter, 32-layer, base LLaMA 3 model with activation and weights quantized to int8. |
36
+ | `llama3_instruct_8b_en ` | 8.03B | 8 billion parameter, 32-layer, instruction tuned LLaMA 3 model. |
37
+ | `llama3_instruct_8b_en_int8 ` | 8.03B | 8 billion parameter, 32-layer, instruction tuned LLaMA 3 model with activation and weights quantized to int8. |
38
+ | `llama3.1_8b` | 8.03B | 8 billion parameter, 32-layer, based LLaMA 3.1 model.|
39
+ | `llama3.1_guard_8b` | 8.03B | 8 billion parameter, 32-layer, LLaMA 3.1 fine-tuned for consent safety classification.|
40
+ | `llama3.1_instruct_8b` | 8.03B | 8 billion parameter, 32-layer, instruction tuned LLaMA 3.1.|
41
+ | `llama3.2_1b` | 1.5B | 1 billion parameter, 16-layer, based LLaMA 3.2 model.|
42
+ | `llama3.2_3b` | 3.6B | 3 billion parameter, 26-layer, based LLaMA 3.2 model.|
43
+ | `llama3.2_guard_1b` | 1.5B | 1 billion parameter, 16-layer, based LLaMA 3.2 model fine-tuned for consent safety classification. |
44
+ | `llama3.2_instruct_1b` | 1.5B | 1 billion parameter, 16-layer, instruction tuned LLaMA 3.2.|
45
+ | `llama3.2_instruct_3b` | 3.6B | 3 billion parameter, 28-layer, instruction tuned LLaMA 3.2.|
46
+
47
+
48
+ ## Prompts
49
+
50
+ Llama-3 "instruct" models are instruction tuned on turn by turn conversations and should be prompted with examples that precisely match the training data. Specifically, you must alternate user and assistant turns that begin and end with special tokens. New lines do matter. See the following for an example:
51
+
52
+ ```python
53
+ prompt = """<|start_header_id|>system<|end_header_id|>
54
+
55
+ You are a helpful AI assistant for travel tips and recommendations<|eot_id|><|start_header_id|>user<|end_header_id|>
56
+
57
+ What can you help me with?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
58
+ """
59
+ ```
60
+
61
+ For more details, please refer to this link: [Llama 3 Model Card & Prompt Formats](https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3).
62
+
63
+ Base models (without instruct in the name) have no specific prompting structure, and should usually be fine-tuned for a specific task.
64
+
65
+ ## Example Usage
66
+ ```python
67
+ import keras
68
+ import keras_hub
69
+ import numpy as np
70
+ ```
71
+
72
+ Use `generate()` to do text generation.
73
+
74
+ ```python
75
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("llama3.2_3b")
76
+ llama_lm.generate("What is Keras?", max_length=500)
77
+
78
+ # Generate with batched prompts.
79
+ llama_lm.generate(["What is Keras?", "Give me your best brownie recipe."], max_length=500)
80
+ ```
81
+
82
+ Compile the `generate()` function with a custom sampler.
83
+
84
+ ```python
85
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("llama3.2_3b")
86
+ llama_lm.compile(sampler="greedy")
87
+ llama_lm.generate("I want to say", max_length=30)
88
+
89
+ llama_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
90
+ llama_lm.generate("I want to say", max_length=30)
91
+ ```
92
+
93
+ Use `generate()` without preprocessing.
94
+
95
+ ```python
96
+ prompt = {
97
+ "token_ids": np.array([[306, 864, 304, 1827, 0, 0, 0, 0, 0, 0]] * 2),
98
+ # Use `"padding_mask"` to indicate values that should not be overridden.
99
+ "padding_mask": np.array([[1, 1, 1, 1, 0, 0, 0, 0, 0, 0]] * 2),
100
+ }
101
+
102
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
103
+ "llama3.2_3b",
104
+ preprocessor=None,
105
+ dtype="bfloat16"
106
+ )
107
+ llama_lm.generate(prompt)
108
+ ```
109
+
110
+ Call `fit()` on a single batch.
111
+
112
+ ```python
113
+ features = ["The quick brown fox jumped.", "I forgot my homework."]
114
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("llama3.2_3b")
115
+ llama_lm.fit(x=features, batch_size=2)
116
+ ```
117
+
118
+ Call `fit()` without preprocessing.
119
+
120
+ ```python
121
+ x = {
122
+ "token_ids": np.array([[450, 4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0]] * 2),
123
+ "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
124
+ }
125
+ y = np.array([[4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0, 0]] * 2)
126
+ sw = np.array([[1, 1, 1, 1, 1, 1, 1, 0, 0, 0]] * 2)
127
+
128
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
129
+ "llama3.2_3b",
130
+ preprocessor=None,
131
+ dtype="bfloat16"
132
+ )
133
+ llama_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)
134
+ ```
135
+
136
+ ## Example Usage with Hugging Face URI
137
+
138
+ ```python
139
+ import keras
140
+ import keras_hub
141
+ import numpy as np
142
+ ```
143
+
144
+ Use `generate()` to do text generation.
145
+
146
+ ```python
147
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("hf://keras/llama3.2_3b")
148
+ llama_lm.generate("What is Keras?", max_length=500)
149
+
150
+ # Generate with batched prompts.
151
+ llama_lm.generate(["What is Keras?", "Give me your best brownie recipe."], max_length=500)
152
+ ```
153
+
154
+ Compile the `generate()` function with a custom sampler.
155
+
156
+ ```python
157
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("hf://keras/llama3.2_3b")
158
+ llama_lm.compile(sampler="greedy")
159
+ llama_lm.generate("I want to say", max_length=30)
160
+
161
+ llama_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
162
+ llama_lm.generate("I want to say", max_length=30)
163
+ ```
164
+
165
+ Use `generate()` without preprocessing.
166
+
167
+ ```python
168
+ prompt = {
169
+ "token_ids": np.array([[306, 864, 304, 1827, 0, 0, 0, 0, 0, 0]] * 2),
170
+ # Use `"padding_mask"` to indicate values that should not be overridden.
171
+ "padding_mask": np.array([[1, 1, 1, 1, 0, 0, 0, 0, 0, 0]] * 2),
172
+ }
173
+
174
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
175
+ "hf://keras/llama3.2_3b",
176
+ preprocessor=None,
177
+ dtype="bfloat16"
178
+ )
179
+ llama_lm.generate(prompt)
180
+ ```
181
+
182
+ Call `fit()` on a single batch.
183
+
184
+ ```python
185
+ features = ["The quick brown fox jumped.", "I forgot my homework."]
186
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("hf://keras/llama3.2_3b")
187
+ llama_lm.fit(x=features, batch_size=2)
188
+ ```
189
+
190
+ Call `fit()` without preprocessing.
191
+
192
+ ```python
193
+ x = {
194
+ "token_ids": np.array([[450, 4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0]] * 2),
195
+ "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
196
+ }
197
+ y = np.array([[4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0, 0]] * 2)
198
+ sw = np.array([[1, 1, 1, 1, 1, 1, 1, 0, 0, 0]] * 2)
199
+
200
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
201
+ "hf://keras/llama3.2_3b",
202
+ preprocessor=None,
203
+ dtype="bfloat16"
204
+ )
205
+ llama_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)
206
+ ```