Skip to content

Commit

Permalink
Merge pull request #34 from ServiceNow/intro-simplified
Browse files Browse the repository at this point in the history
Simplified intro notebook
  • Loading branch information
jpt-sn authored Sep 28, 2024
2 parents 814dbc4 + dab2172 commit d2f842a
Show file tree
Hide file tree
Showing 23 changed files with 1,264 additions and 1,672 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: setup env install lint test test-slow test-all clean
.PHONY: setup env install lint test test-slow test-all clean update-intro update-clean-intro clear-clean-intro

ENV_NAME=tapeagents
PYTHON_VERSION=3.10
Expand Down Expand Up @@ -37,5 +37,8 @@ update-intro:
cp examples/intro_clean.ipynb intro.ipynb
$(CONDA) run --name ${ENV_NAME} jupyter execute --inplace intro.ipynb

clean-intro:
update-clean-intro:
$(CONDA) run --name ${ENV_NAME} jupyter nbconvert intro.ipynb --output=examples/intro_clean.ipynb --to notebook --ClearOutputPreprocessor.enabled=True --ClearMetadataPreprocessor.enabled=True

clear-clean-intro:
$(CONDA) run --name ${ENV_NAME} jupyter nbconvert --inplace examples/intro_clean.ipynb --ClearOutputPreprocessor.enabled=True --ClearMetadataPreprocessor.enabled=True
4 changes: 2 additions & 2 deletions conf/tapeagent/llm/local_llama3_70b.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_target_: tapeagents.llms.LLAMA
_target_: tapeagents.llms.TrainableLLM
use_cache: false
conf:
_target_: tapeagents.llms.LLAMAConfig
_target_: tapeagents.llms.TrainableLLMConfig
base_url: http://0.0.0.0:8080
model_name: meta-llama/Meta-Llama-3-70B-Instruct
context_size: 8000
Expand Down
4 changes: 2 additions & 2 deletions conf/tapeagent/llm/local_llama3_8b.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_target_: tapeagents.llms.LLAMA
_target_: tapeagents.llms.TrainableLLM
use_cache: false
conf:
_target_: tapeagents.llms.LLAMAConfig
_target_: tapeagents.llms.TrainableLLMConfig
base_url: http://0.0.0.0:8080
model_name: meta-llama/Meta-Llama-3-8B-Instruct
context_size: 8000
Expand Down
4 changes: 2 additions & 2 deletions conf/tapeagent/llm/local_mixtral_8x22b.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_target_: tapeagents.llms.LLAMA
_target_: tapeagents.llms.TrainableLLM
use_cache: false
conf:
_target_: tapeagents.llms.LLAMAConfig
_target_: tapeagents.llms.TrainableLLMConfig
base_url: http://0.0.0.0:8080
model_name: mistralai/Mixtral-8x22B-v0.1
context_size: 8000
Expand Down
8 changes: 8 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 1. Copy this file to your .env file that is gitignored to keep your keys safe
# 2. In your .env only, uncomment and fill the following lines with your keys

# OPENAI_API_KEY="" # put your https://platform.openai.com/ key here
# OPENAI_ORGANIZATION="" # optional if you use your personal key

# TOGETHER_API_KEY=""
# HF_TOKEN=""
4 changes: 2 additions & 2 deletions examples/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tapeagents.agent import Agent, Node
from tapeagents.core import SetNextNode, Prompt, Tape
from tapeagents.dialog_tape import AssistantStep, AssistantThought, DialogTape, UserStep
from tapeagents.llms import LLAMA, LLM, LLMStream
from tapeagents.llms import TrainableLLM, LLM, LLMStream


def hello_world(llm: LLM):
Expand Down Expand Up @@ -92,7 +92,7 @@ def generate_steps(self, agent, tape: Tape, llm_stream: LLMStream):


if __name__ == "__main__":
llm = LLAMA(
llm = TrainableLLM(
base_url="https://api.together.xyz",
model_name="meta-llama/Meta-Llama-3-70B-Instruct-Turbo",
tokenizer_name="meta-llama/Meta-Llama-3-70B-Instruct",
Expand Down
4 changes: 2 additions & 2 deletions examples/batch_add_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tapeagents.batch import ObsLayerConfig, batch_add_observations
from tapeagents.dialog_tape import AssistantStep, DialogTape, SystemStep, UserStep
from tapeagents.io import save_tapes
from tapeagents.llms import LLAMA, LLM
from tapeagents.llms import TrainableLLM, LLM

from .llama_user import LLAMAUserModel

Expand Down Expand Up @@ -40,7 +40,7 @@ def try_batch_add_observations(llm: LLM):

if __name__ == "__main__":
try_batch_add_observations(
LLAMA(
TrainableLLM(
base_url="https://api.together.xyz",
model_name="meta-llama/Llama-3-8b-chat-hf",
parameters=dict(temperature=0.7, max_tokens=512),
Expand Down
4 changes: 2 additions & 2 deletions examples/batch_main_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tapeagents.dialog_tape import DialogTape, SystemStep, UserStep
from tapeagents.environment import EmptyEnvironment
from tapeagents.io import save_tapes
from tapeagents.llms import LLAMA, LLM
from tapeagents.llms import TrainableLLM, LLM

from .llama_agent import LLAMAChatBot

Expand Down Expand Up @@ -33,7 +33,7 @@ def try_batch_main_loop(llm: LLM):

if __name__ == "__main__":
try_batch_main_loop(
LLAMA(
TrainableLLM(
base_url="https://api.together.xyz",
model_name="meta-llama/Llama-3-8b-chat-hf",
parameters=dict(temperature=0.7, max_tokens=512),
Expand Down
4 changes: 2 additions & 2 deletions examples/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from tapeagents.team import TeamAgent, TeamTape
from tapeagents.studio import Studio
from tapeagents.llms import LLAMA, LLM
from tapeagents.llms import TrainableLLM, LLM
from tapeagents.rendering import PrettyRenderer


Expand All @@ -26,7 +26,7 @@ def try_chat(llm: LLM, studio: bool):


if __name__ == "__main__":
llm = LLAMA(
llm = TrainableLLM(
base_url="https://api.together.xyz",
model_name="meta-llama/Meta-Llama-3-70B-Instruct-Turbo",
parameters=dict(temperature=0.7, max_tokens=512),
Expand Down
4 changes: 2 additions & 2 deletions examples/continue_tapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tapeagents.batch import generate_tapes
from tapeagents.dialog_tape import AssistantStep, DialogTape, SystemStep, UserStep
from tapeagents.environment import EmptyEnvironment
from tapeagents.llms import LLAMA, LLM
from tapeagents.llms import TrainableLLM, LLM

from .llama_agent import LLAMAChatBot
from .llama_user import LLAMAUserModel
Expand Down Expand Up @@ -48,7 +48,7 @@ def try_continue_tapes(llm: LLM):

if __name__ == "__main__":
try_continue_tapes(
LLAMA(
TrainableLLM(
base_url="https://api.together.xyz",
model_name="meta-llama/Llama-3-8b-chat-hf",
parameters=dict(temperature=0.7, max_tokens=512),
Expand Down
6 changes: 3 additions & 3 deletions examples/delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from tapeagents.agent import Agent, AgentEvent
from tapeagents.core import Action, Prompt, Tape, Thought
from tapeagents.llms import LLAMA, LLM, LLMStream
from tapeagents.llms import TrainableLLM, LLM, LLMStream

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

Expand Down Expand Up @@ -86,7 +86,7 @@ def delegate(self, tape: ExampleTape) -> Agent[ExampleTape]:
raise ValueError(f"Invalid state {state}")


def try_delegation(llama: LLAMA):
def try_delegation(llama: TrainableLLM):
tape = ExampleTape(context=EXAMPLE_TEXT)
with open("start_tape.json", "w") as f:
json.dump(tape.model_dump(), f, indent=2)
Expand All @@ -104,7 +104,7 @@ def try_delegation(llama: LLAMA):

if __name__ == "__main__":
try_delegation(
LLAMA(
TrainableLLM(
base_url="https://api.together.xyz",
model_name="meta-llama/Meta-Llama-3-70B-Instruct-Turbo",
parameters=dict(temperature=0.7, max_tokens=512),
Expand Down
4 changes: 2 additions & 2 deletions examples/delegate_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Tape,
Thought,
)
from tapeagents.llms import LLAMA, LLM, LLMStream
from tapeagents.llms import TrainableLLM, LLM, LLMStream
from tapeagents.view import Call, Respond, TapeViewStack

EXAMPLE_TEXT = """I am a text with some verbs like running, jumping, and swimming."""
Expand Down Expand Up @@ -224,7 +224,7 @@ def make_analyze_text_chain(llm: LLM):


def main():
llama = LLAMA(
llama = TrainableLLM(
base_url="https://api.together.xyz",
model_name="meta-llama/Meta-Llama-3-70B-Instruct-Turbo",
tokenizer_name="meta-llama/Meta-Llama-3-70B-Instruct",
Expand Down
8 changes: 4 additions & 4 deletions examples/gsm8k_tuning/eval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"from termcolor import colored\n",
"from tqdm import tqdm\n",
"\n",
"from tapeagents.llms import LLAMA\n"
"from tapeagents.llms import TrainableLLM\n"
]
},
{
Expand Down Expand Up @@ -90,7 +90,7 @@
"# run inference: vllm serve meta-llama/Meta-Llama-3.1-8B-Instruct\n",
"untuned_agent = MathAgent(\n",
" llms={\n",
" \"default\": LLAMA(\n",
" \"default\": TrainableLLM(\n",
" base_url=\"http://localhost:8000\",\n",
" model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\",\n",
" tokenizer_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\",\n",
Expand Down Expand Up @@ -415,7 +415,7 @@
"# run inference: vllm serve gsm8k/tuning/llama31_70b_train_t02/tune1/intermediate/800/\n",
"tuned_agent = MathAgent(\n",
" llms={\n",
" \"default\": LLAMA(\n",
" \"default\": TrainableLLM(\n",
" base_url=\"http://localhost:8000\",\n",
" model_name=\"gsm8k/tuning/llama31_70b_train_t02/tune1/intermediate/800/\",\n",
" tokenizer_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\",\n",
Expand Down Expand Up @@ -731,7 +731,7 @@
"outputs": [],
"source": [
"# check teacher model\n",
"big_llm = LLAMA(\n",
"big_llm = TrainableLLM(\n",
" base_url=\"https://api.together.xyz\",\n",
" model_name=\"meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo\",\n",
" tokenizer_name=\"meta-llama/Meta-Llama-3.1-70B-Instruct\",\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/gsm8k_tuning/finetune.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"\n",
"from tapeagents.core import TrainingText\n",
"from math_agent import ActionExecutionFailure, MathAgent, MathTape\n",
"from tapeagents.llms import LLAMA\n"
"from tapeagents.llms import TrainableLLM\n"
]
},
{
Expand All @@ -32,7 +32,7 @@
"# We need the agent to cut tapes into training samples\n",
"agent = MathAgent(\n",
" llms={\n",
" \"default\": LLAMA(\n",
" \"default\": TrainableLLM(\n",
" base_url=\"https://api.together.xyz\",\n",
" model_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo\",\n",
" tokenizer_name=\"meta-llama/Meta-Llama-3.1-8B-Instruct\",\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/gsm8k_tuning/produce_tapes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"from termcolor import colored\n",
"from tqdm import tqdm\n",
"\n",
"from tapeagents.llms import LLAMA\n"
"from tapeagents.llms import TrainableLLM\n"
]
},
{
Expand Down Expand Up @@ -52,7 +52,7 @@
"np.random.seed(42)\n",
"np.random.shuffle(samples) # type: ignore\n",
"\n",
"llm = LLAMA(\n",
"llm = TrainableLLM(\n",
" base_url=\"https://api.together.xyz\",\n",
" model_name=\"meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo\",\n",
" tokenizer_name=\"meta-llama/Meta-Llama-3.1-70B-Instruct\",\n",
Expand Down
Loading

0 comments on commit d2f842a

Please sign in to comment.