Divyasreepat commited on
Commit
92e42db
1 Parent(s): d40e46c

Update README.md with new model card content

Browse files
Files changed (1) hide show
  1. README.md +193 -16
README.md CHANGED
@@ -1,19 +1,196 @@
1
  ---
2
  library_name: keras-hub
3
  ---
4
- 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.
5
- Model config:
6
- * **name:** llama_backbone
7
- * **trainable:** True
8
- * **vocabulary_size:** 128256
9
- * **num_layers:** 32
10
- * **num_query_heads:** 32
11
- * **hidden_dim:** 4096
12
- * **intermediate_dim:** 14336
13
- * **rope_max_wavelength:** 500000.0
14
- * **rope_scaling_factor:** 1.0
15
- * **num_key_value_heads:** 8
16
- * **layer_norm_epsilon:** 1e-05
17
- * **dropout:** 0
18
-
19
- 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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  library_name: keras-hub
3
  ---
4
+ ### Model Overview
5
+ 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.
6
+
7
+ 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).
8
+
9
+ ## Links
10
+
11
+ * [Llama 3 API Documentation](https://keras.io/api/keras_hub/models/llama3/)
12
+ * [Llama 3 Model Card & Prompt Formats](https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-3)
13
+ * [KerasHub Beginner Guide](https://keras.io/guides/keras_hub/getting_started/)
14
+ * [KerasHub Model Publishing Guide](https://keras.io/guides/keras_hub/upload/)
15
+
16
+ ## Installation
17
+
18
+ Keras and KerasHub can be installed with:
19
+
20
+ ```
21
+ pip install -U -q keras-hub
22
+ pip install -U -q keras>=3
23
+ ```
24
+
25
+ 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.
26
+
27
+ ## Presets
28
+
29
+ The following model checkpoints are provided by the Keras team. Full code examples for each are available below.
30
+
31
+ | Preset name | Parameters | Description |
32
+ |-----------------------|------------|---------------|
33
+ |` llama3_8b_en ` | 8.03B | 8 billion parameter, 32-layer, base LLaMA 3 model. |
34
+ |` llama3_8b_en_int8 ` | 8.03B | 8 billion parameter, 32-layer, base LLaMA 3 model with activation and weights quantized to int8. |
35
+ | `llama3_instruct_8b_en ` | 8.03B | 8 billion parameter, 32-layer, instruction tuned LLaMA 3 model. |
36
+ | `llama3_instruct_8b_en_int8 ` | 8.03B | 8 billion parameter, 32-layer, instruction tuned LLaMA 3 model with activation and weights quantized to int8. |
37
+
38
+ ## Prompts
39
+
40
+ 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:
41
+
42
+ ```python
43
+ prompt = """<|start_header_id|>system<|end_header_id|>
44
+
45
+ You are a helpful AI assistant for travel tips and recommendations<|eot_id|><|start_header_id|>user<|end_header_id|>
46
+
47
+ What can you help me with?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
48
+ """
49
+ ```
50
+
51
+ 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).
52
+
53
+ Base models (without instruct in the name) have no specific prompting structure, and should usually be fine-tuned for a specific task.
54
+
55
+ ### Example Usage
56
+ ```python
57
+ import keras
58
+ import keras_hub
59
+ import numpy as np
60
+ ```
61
+
62
+ Use `generate()` to do text generation.
63
+
64
+ ```python
65
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("llama3_instruct_8b_en")
66
+ llama_lm.generate("What is Keras?", max_length=500)
67
+
68
+ # Generate with batched prompts.
69
+ llama_lm.generate(["What is Keras?", "Give me your best brownie recipe."], max_length=500)
70
+ ```
71
+
72
+ Compile the `generate()` function with a custom sampler.
73
+
74
+ ```python
75
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("llama3_instruct_8b_en")
76
+ llama_lm.compile(sampler="greedy")
77
+ llama_lm.generate("I want to say", max_length=30)
78
+
79
+ llama_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
80
+ llama_lm.generate("I want to say", max_length=30)
81
+ ```
82
+
83
+ Use `generate()` without preprocessing.
84
+
85
+ ```python
86
+ prompt = {
87
+ "token_ids": np.array([[306, 864, 304, 1827, 0, 0, 0, 0, 0, 0]] * 2),
88
+ # Use `"padding_mask"` to indicate values that should not be overridden.
89
+ "padding_mask": np.array([[1, 1, 1, 1, 0, 0, 0, 0, 0, 0]] * 2),
90
+ }
91
+
92
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
93
+ "llama3_instruct_8b_en",
94
+ preprocessor=None,
95
+ dtype="bfloat16"
96
+ )
97
+ llama_lm.generate(prompt)
98
+ ```
99
+
100
+ Call `fit()` on a single batch.
101
+
102
+ ```python
103
+ features = ["The quick brown fox jumped.", "I forgot my homework."]
104
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("llama3_instruct_8b_en")
105
+ llama_lm.fit(x=features, batch_size=2)
106
+ ```
107
+
108
+ Call `fit()` without preprocessing.
109
+
110
+ ```python
111
+ x = {
112
+ "token_ids": np.array([[450, 4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0]] * 2),
113
+ "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
114
+ }
115
+ y = np.array([[4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0, 0]] * 2)
116
+ sw = np.array([[1, 1, 1, 1, 1, 1, 1, 0, 0, 0]] * 2)
117
+
118
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
119
+ "llama3_instruct_8b_en",
120
+ preprocessor=None,
121
+ dtype="bfloat16"
122
+ )
123
+ llama_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)
124
+ ```
125
+
126
+ ## Example Usage with Hugging Face URI
127
+
128
+ ```python
129
+ import keras
130
+ import keras_hub
131
+ import numpy as np
132
+ ```
133
+
134
+ Use `generate()` to do text generation.
135
+
136
+ ```python
137
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("hf://keras/llama3_instruct_8b_en")
138
+ llama_lm.generate("What is Keras?", max_length=500)
139
+
140
+ # Generate with batched prompts.
141
+ llama_lm.generate(["What is Keras?", "Give me your best brownie recipe."], max_length=500)
142
+ ```
143
+
144
+ Compile the `generate()` function with a custom sampler.
145
+
146
+ ```python
147
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("hf://keras/llama3_instruct_8b_en")
148
+ llama_lm.compile(sampler="greedy")
149
+ llama_lm.generate("I want to say", max_length=30)
150
+
151
+ llama_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
152
+ llama_lm.generate("I want to say", max_length=30)
153
+ ```
154
+
155
+ Use `generate()` without preprocessing.
156
+
157
+ ```python
158
+ prompt = {
159
+ "token_ids": np.array([[306, 864, 304, 1827, 0, 0, 0, 0, 0, 0]] * 2),
160
+ # Use `"padding_mask"` to indicate values that should not be overridden.
161
+ "padding_mask": np.array([[1, 1, 1, 1, 0, 0, 0, 0, 0, 0]] * 2),
162
+ }
163
+
164
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
165
+ "hf://keras/llama3_instruct_8b_en",
166
+ preprocessor=None,
167
+ dtype="bfloat16"
168
+ )
169
+ llama_lm.generate(prompt)
170
+ ```
171
+
172
+ Call `fit()` on a single batch.
173
+
174
+ ```python
175
+ features = ["The quick brown fox jumped.", "I forgot my homework."]
176
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset("hf://keras/llama3_instruct_8b_en")
177
+ llama_lm.fit(x=features, batch_size=2)
178
+ ```
179
+
180
+ Call `fit()` without preprocessing.
181
+
182
+ ```python
183
+ x = {
184
+ "token_ids": np.array([[450, 4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0]] * 2),
185
+ "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
186
+ }
187
+ y = np.array([[4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0, 0]] * 2)
188
+ sw = np.array([[1, 1, 1, 1, 1, 1, 1, 0, 0, 0]] * 2)
189
+
190
+ llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
191
+ "hf://keras/llama3_instruct_8b_en",
192
+ preprocessor=None,
193
+ dtype="bfloat16"
194
+ )
195
+ llama_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)
196
+ ```