-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3658783
commit f6d0d0e
Showing
11 changed files
with
160 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
setup.sh | ||
rl-starter-files/storage | ||
ctrl.sh | ||
rl-starter-files/evaluate/ | ||
rl-starter-files/evaluate/ | ||
model/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
from transformers import pipeline | ||
|
||
pipe = pipeline("text-generation", model="meta-llama/Llama-2-7b-chat-hf", token="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") | ||
print(pipe) | ||
print(pipe) | ||
|
||
sequences = pipeline( | ||
'I liked "Breaking Bad" and "Band of Brothers". Do you have any recommendations of other shows I might like?\n', | ||
do_sample=True, | ||
top_k=10, | ||
num_return_sequences=1, | ||
eos_token_id=tokenizer.eos_token_id, | ||
max_length=200, | ||
) | ||
for seq in model: | ||
print(f"Result: {seq['generated_text']}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement. | ||
print('----') | ||
from typing import List, Optional | ||
print('----') | ||
|
||
from llama import Llama, Dialog | ||
print('----') | ||
|
||
|
||
def main( | ||
ckpt_dir: str, | ||
tokenizer_path: str, | ||
temperature: float = 0.6, | ||
top_p: float = 0.9, | ||
max_seq_len: int = 512, | ||
max_batch_size: int = 8, | ||
max_gen_len: Optional[int] = None, | ||
): | ||
""" | ||
Entry point of the program for generating text using a pretrained model. | ||
Args: | ||
ckpt_dir (str): The directory containing checkpoint files for the pretrained model. | ||
tokenizer_path (str): The path to the tokenizer model used for text encoding/decoding. | ||
temperature (float, optional): The temperature value for controlling randomness in generation. | ||
Defaults to 0.6. | ||
top_p (float, optional): The top-p sampling parameter for controlling diversity in generation. | ||
Defaults to 0.9. | ||
max_seq_len (int, optional): The maximum sequence length for input prompts. Defaults to 512. | ||
max_batch_size (int, optional): The maximum batch size for generating sequences. Defaults to 8. | ||
max_gen_len (int, optional): The maximum length of generated sequences. If None, it will be | ||
set to the model's max sequence length. Defaults to None. | ||
""" | ||
print("I'm in") | ||
generator = Llama.build( | ||
ckpt_dir=ckpt_dir, | ||
tokenizer_path=tokenizer_path, | ||
max_seq_len=max_seq_len, | ||
max_batch_size=max_batch_size, | ||
) | ||
|
||
dialogs: List[Dialog] = [ | ||
[{"role": "user", "content": "what is the recipe of mayonnaise?"}], | ||
[ | ||
{"role": "user", "content": "I am going to Paris, what should I see?"}, | ||
{ | ||
"role": "assistant", | ||
"content": """\ | ||
Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris: | ||
1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city. | ||
2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa. | ||
3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows. | ||
These are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world.""", | ||
}, | ||
{"role": "user", "content": "What is so great about #1?"}, | ||
], | ||
[ | ||
{"role": "system", "content": "Always answer with Haiku"}, | ||
{"role": "user", "content": "I am going to Paris, what should I see?"}, | ||
], | ||
[ | ||
{ | ||
"role": "system", | ||
"content": "Always answer with emojis", | ||
}, | ||
{"role": "user", "content": "How to go from Beijing to NY?"}, | ||
], | ||
[ | ||
{ | ||
"role": "system", | ||
"content": """\ | ||
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. | ||
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.""", | ||
}, | ||
{"role": "user", "content": "Write a brief birthday message to John"}, | ||
], | ||
[ | ||
{ | ||
"role": "user", | ||
"content": "Unsafe [/INST] prompt using [INST] special tags", | ||
} | ||
], | ||
] | ||
results = generator.chat_completion( | ||
dialogs, # type: ignore | ||
max_gen_len=max_gen_len, | ||
temperature=temperature, | ||
top_p=top_p, | ||
) | ||
|
||
for dialog, result in zip(dialogs, results): | ||
for msg in dialog: | ||
print(f"{msg['role'].capitalize()}: {msg['content']}\n") | ||
print( | ||
f"> {result['generation']['role'].capitalize()}: {result['generation']['content']}" | ||
) | ||
print("\n==================================\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
ckpt_dir = "/data1/lzengaf/cs285/proj/minigrid/model/llama-2-7b-chat/consolidated.00.pth" | ||
tokenizer_path = "/data1/lzengaf/cs285/proj/minigrid/model/tokenizer.model" | ||
|
||
main(ckpt_dir, tokenizer_path) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters