Views
No views yet
pip install -U -q keras-hub
pip install -U -q keras| Preset name | Parameters | Description |
|---|---|---|
llama3_8b_en | 8.03B | 8 billion parameter, 32-layer, base LLaMA 3 model. |
llama3_8b_en_int8 | 8.03B | 8 billion parameter, 32-layer, base LLaMA 3 model with activation and weights quantized to int8. |
llama3_instruct_8b_en | 8.03B | 8 billion parameter, 32-layer, instruction tuned LLaMA 3 model. |
llama3_instruct_8b_en_int8 | 8.03B | 8 billion parameter, 32-layer, instruction tuned LLaMA 3 model with activation and weights quantized to int8. |
llama3.1_8b | 8.03B | 8 billion parameter, 32-layer, based LLaMA 3.1 model. |
llama3.1_guard_8b | 8.03B | 8 billion parameter, 32-layer, LLaMA 3.1 fine-tuned for consent safety classification. |
llama3.1_instruct_8b | 8.03B | 8 billion parameter, 32-layer, instruction tuned LLaMA 3.1. |
llama3.2_1b | 1.5B | 1 billion parameter, 16-layer, based LLaMA 3.2 model. |
llama3.2_3b | 3.6B | 3 billion parameter, 26-layer, based LLaMA 3.2 model. |
llama3.2_guard_1b | 1.5B | 1 billion parameter, 16-layer, based LLaMA 3.2 model fine-tuned for consent safety classification. |
llama3.2_instruct_1b | 1.5B | 1 billion parameter, 16-layer, instruction tuned LLaMA 3.2. |
llama3.2_instruct_3b | 3.6B | 3 billion parameter, 28-layer, instruction tuned LLaMA 3.2. |
1prompt = """<|start_header_id|>system<|end_header_id|>
2
3You are a helpful AI assistant for travel tips and recommendations<|eot_id|><|start_header_id|>user<|end_header_id|>
4
5What can you help me with?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
6"""1import keras
2import keras_hub
3import numpy as npgenerate() to do text generation.1llama_lm = keras_hub.models.Llama3CausalLM.from_preset("llama3_instruct_8b_en")
2llama_lm.generate("What is Keras?", max_length=500)
3
4# Generate with batched prompts.
5llama_lm.generate(["What is Keras?", "Give me your best brownie recipe."], max_length=500)generate() function with a custom sampler.1llama_lm = keras_hub.models.Llama3CausalLM.from_preset("llama3_instruct_8b_en")
2llama_lm.compile(sampler="greedy")
3llama_lm.generate("I want to say", max_length=30)
4
5llama_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
6llama_lm.generate("I want to say", max_length=30)generate() without preprocessing.1prompt = {
2 "token_ids": np.array([[306, 864, 304, 1827, 0, 0, 0, 0, 0, 0]] * 2),
3 # Use `"padding_mask"` to indicate values that should not be overridden.
4 "padding_mask": np.array([[1, 1, 1, 1, 0, 0, 0, 0, 0, 0]] * 2),
5}
6
7llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
8 "llama3_instruct_8b_en",
9 preprocessor=None,
10 dtype="bfloat16"
11)
12llama_lm.generate(prompt)fit() on a single batch.1features = ["The quick brown fox jumped.", "I forgot my homework."]
2llama_lm = keras_hub.models.Llama3CausalLM.from_preset("llama3_instruct_8b_en")
3llama_lm.fit(x=features, batch_size=2)fit() without preprocessing.1x = {
2 "token_ids": np.array([[450, 4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0]] * 2),
3 "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
4}
5y = np.array([[4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0, 0]] * 2)
6sw = np.array([[1, 1, 1, 1, 1, 1, 1, 0, 0, 0]] * 2)
7
8llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
9 "llama3_instruct_8b_en",
10 preprocessor=None,
11 dtype="bfloat16"
12)
13llama_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)1import keras
2import keras_hub
3import numpy as npgenerate() to do text generation.1llama_lm = keras_hub.models.Llama3CausalLM.from_preset("hf://keras/llama3_instruct_8b_en")
2llama_lm.generate("What is Keras?", max_length=500)
3
4# Generate with batched prompts.
5llama_lm.generate(["What is Keras?", "Give me your best brownie recipe."], max_length=500)generate() function with a custom sampler.1llama_lm = keras_hub.models.Llama3CausalLM.from_preset("hf://keras/llama3_instruct_8b_en")
2llama_lm.compile(sampler="greedy")
3llama_lm.generate("I want to say", max_length=30)
4
5llama_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
6llama_lm.generate("I want to say", max_length=30)generate() without preprocessing.1prompt = {
2 "token_ids": np.array([[306, 864, 304, 1827, 0, 0, 0, 0, 0, 0]] * 2),
3 # Use `"padding_mask"` to indicate values that should not be overridden.
4 "padding_mask": np.array([[1, 1, 1, 1, 0, 0, 0, 0, 0, 0]] * 2),
5}
6
7llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
8 "hf://keras/llama3_instruct_8b_en",
9 preprocessor=None,
10 dtype="bfloat16"
11)
12llama_lm.generate(prompt)fit() on a single batch.1features = ["The quick brown fox jumped.", "I forgot my homework."]
2llama_lm = keras_hub.models.Llama3CausalLM.from_preset("hf://keras/llama3_instruct_8b_en")
3llama_lm.fit(x=features, batch_size=2)fit() without preprocessing.1x = {
2 "token_ids": np.array([[450, 4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0]] * 2),
3 "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
4}
5y = np.array([[4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0, 0]] * 2)
6sw = np.array([[1, 1, 1, 1, 1, 1, 1, 0, 0, 0]] * 2)
7
8llama_lm = keras_hub.models.Llama3CausalLM.from_preset(
9 "hf://keras/llama3_instruct_8b_en",
10 preprocessor=None,
11 dtype="bfloat16"
12)
13llama_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)