Skip to content

Commit 9f14be6

Browse files
author
Dylan Huang
committed
implement logger and use in agent rollout processor
1 parent 0f8dc1f commit 9f14be6

10 files changed

Lines changed: 857 additions & 10 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"messages":[{"role":"system","content":"You are a helpful assistant that can answer questions about Fireworks.\nALWAYS provide code or commands to execute to answer the question."},{"role":"user","content":"Can you teach me about how to manage deployments on Fireworks"},{"role":"assistant","content":"I'll help you learn about managing deployments on Fireworks. Let me search for comprehensive information about deployment management.","tool_calls":[{"id":"functions.search:0","type":"function","function":{"name":"search","arguments":"{\"query\": \"deployment management Fireworks AI\"}"}}]},{"role":"tool","content":"Title: Fireworks AI Developer Platform\nLink: https://docs.fireworks.ai/getting-started/introduction\nContent: Fireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\n","tool_call_id":"functions.search:0"},{"role":"assistant","content":"Let me search for more specific information about deployment management features and processes.","tool_calls":[{"id":"functions.search:1","type":"function","function":{"name":"search","arguments":"{\"query\": \"deploy models Fireworks AI deployment management\"}"}}]},{"role":"tool","content":"Title: Fireworks AI Developer Platform\nLink: https://docs.fireworks.ai/getting-started/introduction\nContent: Fireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\n","tool_call_id":"functions.search:1"},{"role":"assistant","content":"Let me search for more specific deployment-related terms:","tool_calls":[{"id":"functions.search:0","type":"function","function":{"name":"search","arguments":"{\"query\": \"inference endpoints deployment Fireworks AI\"}"}}]},{"role":"tool","content":"Title: Fireworks AI Developer Platform\nLink: https://docs.fireworks.ai/getting-started/introduction\nContent: Fireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\n","tool_call_id":"functions.search:0"},{"role":"assistant","content":"Let me try searching for more specific deployment management topics:","tool_calls":[{"id":"functions.search:0","type":"function","function":{"name":"search","arguments":"{\"query\": \"model deployment configuration scaling Fireworks\"}"}}]},{"role":"tool","content":"Title: What should I expect for deployment and scaling performance?\nLink: https://docs.fireworks.ai/faq-new/deployment-infrastructure/what-should-i-expect-for-deployment-and-scaling-performance\nContent: Initial deployment : Should complete within minutes Scaling from zero : You may experience brief availability delays while the system scales up Troubleshooting : If deployment takes over 1 hour, this typically indicates a crash and should be investigated Best practice : Monitor deployment status and contact support if deployment times are unusually long\n\nInitial deployment : Should complete within minutes Scaling from zero : You may experience brief availability delays while the system scales up Troubleshooting : If deployment takes over 1 hour, this typically indicates a crash and should be investigated Best practice : Monitor deployment status and contact support if deployment times are unusually long\n\nWhat should I expect for deployment and scaling performance?\nInitial deployment : Should complete within minutes Scaling from zero : You may experience brief availability delays while the system scales up Troubleshooting : If deployment takes over 1 hour, this typically indicates a crash and should be investigated Best practice : Monitor deployment status and contact support if deployment times are unusually long\n\n","tool_call_id":"functions.search:0"},{"role":"assistant","content":null,"tool_calls":[{"id":"functions.search:1","type":"function","function":{"name":"search","arguments":"{\"query\": \"deployment status monitoring Fireworks AI\"}"}}]},{"role":"tool","content":"Title: Fireworks AI Developer Platform\nLink: https://docs.fireworks.ai/getting-started/introduction\nContent: Fireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\n","tool_call_id":"functions.search:1"},{"role":"assistant","content":null,"tool_calls":[{"id":"functions.search:0","type":"function","function":{"name":"search","arguments":"{\"query\": \"custom model deployment Fireworks AI\"}"}}]},{"role":"tool","content":"Title: Does Fireworks support custom base models?\nLink: https://docs.fireworks.ai/faq-new/models-inference/does-fireworks-support-custom-base-models\nContent: Yes, custom base models can be deployed via firectl . You can learn more about custom model deployment in our guide on uploading custom models.\n\nYes, custom base models can be deployed via firectl . You can learn more about custom model deployment in our guide on uploading custom models.\n\nDoes Fireworks support custom base models?\nYes, custom base models can be deployed via firectl . You can learn more about custom model deployment in our guide on uploading custom models.\n\n","tool_call_id":"functions.search:0"},{"role":"assistant","content":null,"tool_calls":[{"id":"functions.search:0","type":"function","function":{"name":"search","arguments":"{\"query\": \"firectl deployment tool Fireworks AI\"}"}}]},{"role":"tool","content":"Title: Fireworks AI Developer Platform\nLink: https://docs.fireworks.ai/getting-started/introduction\nContent: Fireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\n","tool_call_id":"functions.search:0"},{"role":"assistant","content":"Let me search for more specific deployment management commands and tools:","tool_calls":[{"id":"functions.search:0","type":"function","function":{"name":"search","arguments":"{\"query\": \"deployment commands CLI Fireworks AI\"}"}}]},{"role":"tool","content":"Title: Fireworks AI Developer Platform\nLink: https://docs.fireworks.ai/getting-started/introduction\nContent: Fireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\nFireworks AI is the best platform for building AI product experiences with open source AI models. You can run and customize AI models with just a few lines of code!\n\n","tool_call_id":"functions.search:0"},{"role":"assistant","content":"Let me try searching for deployment configuration and management:","tool_calls":[{"id":"functions.search:0","type":"function","function":{"name":"search","arguments":"{\"query\": \"deployment configuration YAML JSON Fireworks\"}"}}]},{"role":"tool","content":"Title: Create a fine-tuning job\nLink: https://docs.fireworks.ai/tools-sdks/firectl/commands/create-finetune-job\nContent: Creates a fine-tuning job on Fireworks AI platform with the provided configuration yaml.\n\nCreates a fine-tuning job on Fireworks AI platform with the provided configuration yaml.\n\nCreates a fine-tuning job on Fireworks AI platform with the provided configuration yaml.\n\n","tool_call_id":"functions.search:0"},{"role":"assistant","content":"Based on my search results, here's what I can teach you about managing deployments on Fireworks AI:\n\n## Deployment Management on Fireworks AI\n\n### 1. **Deployment Performance Expectations**\n- **Initial deployment**: Should complete within minutes\n- **Scaling from zero**: May experience brief availability delays while the system scales up\n- **Troubleshooting**: If deployment takes over 1 hour, this typically indicates a crash and should be investigated\n- **Best practice**: Monitor deployment status and contact support if deployment times are unusually long\n\n### 2. **Custom Model Deployment**\nFireworks AI supports custom base models through `firectl` - their deployment tool. You can deploy custom models using this command-line interface.\n\n### 3. **Deployment Tools**\n- **firectl**: The primary deployment tool for managing models on Fireworks AI\n- Used for both standard and custom model deployments\n- Supports configuration via YAML files\n\n### 4. **Monitoring and Management**\n- Monitor deployment status regularly\n- Contact support for unusually long deployment times\n- Watch for scaling delays when starting from zero instances\n\n### 5. **Configuration Management**\nDeployments can be configured using YAML configuration files, similar to how fine-tuning jobs are configured.\n\n## Next Steps for Managing Deployments\n\nTo get started with deployment management, you should:\n\n1. **Install firectl**: The Fireworks AI command-line tool\n2. **Prepare your model**: Ensure your model is properly formatted and ready for deployment\n3. **Create deployment configuration**: Use YAML files to define deployment parameters\n4. **Monitor deployment**: Use built-in monitoring tools to track deployment status\n5. **Scale as needed**: Configure auto-scaling based on your traffic patterns\n\nWould you like me to search for more specific information about any of these deployment management aspects, such as specific firectl commands or configuration examples?","tool_calls":[]}],"input_metadata":{"row_id":"feel-might-gaseous-picture"},"created_at":"2025-08-05T10:43:36.343980"}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from eval_protocol.dataset_logger.local_fs_dataset_logger_adapter import LocalFSDatasetLoggerAdapter
2+
3+
default_logger = LocalFSDatasetLoggerAdapter()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from abc import ABC, abstractmethod
2+
from typing import TYPE_CHECKING, List, Optional
3+
4+
if TYPE_CHECKING:
5+
from eval_protocol.models import EvaluationRow
6+
7+
8+
class DatasetLogger(ABC):
9+
"""
10+
Abstract base class for logging EvaluationRow objects.
11+
Implementations should provide methods for storing and retrieving logs.
12+
"""
13+
14+
@abstractmethod
15+
def log(self, row: "EvaluationRow") -> None:
16+
"""
17+
Store a single EvaluationRow log.
18+
19+
Args:
20+
row (EvaluationRow): The evaluation row to log.
21+
"""
22+
pass
23+
24+
@abstractmethod
25+
def read(self, row_id: Optional[str] = None) -> List["EvaluationRow"]:
26+
"""
27+
Retrieve EvaluationRow logs.
28+
29+
Args:
30+
row_id (Optional[str]): If provided, filter logs by this row_id.
31+
32+
Returns:
33+
List[EvaluationRow]: List of retrieved evaluation rows.
34+
"""
35+
pass
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
from datetime import datetime, timezone
2+
import json
3+
import os
4+
import tempfile
5+
import shutil
6+
from typing import TYPE_CHECKING, List, Optional
7+
from eval_protocol.common_utils import load_jsonl
8+
from eval_protocol.dataset_logger.dataset_logger import DatasetLogger
9+
10+
if TYPE_CHECKING:
11+
from eval_protocol.models import EvaluationRow
12+
13+
14+
class LocalFSDatasetLoggerAdapter(DatasetLogger):
15+
"""
16+
Logger that stores logs in the local filesystem.
17+
"""
18+
19+
EVAL_PROTOCOL_DIR = ".eval_protocol"
20+
PYTHON_FILES = ["pyproject.toml", "requirements.txt"]
21+
DATASETS_DIR = "datasets"
22+
23+
def __init__(self):
24+
# recursively look up for a .eval_protocol directory
25+
current_dir = os.path.dirname(os.path.abspath(__file__))
26+
while current_dir != "/":
27+
if os.path.exists(os.path.join(current_dir, self.EVAL_PROTOCOL_DIR)):
28+
self.log_dir = os.path.join(current_dir, self.EVAL_PROTOCOL_DIR)
29+
break
30+
current_dir = os.path.dirname(current_dir)
31+
32+
# if not found, recursively look up until a pyproject.toml or requirements.txt is found
33+
current_dir = os.path.dirname(os.path.abspath(__file__))
34+
while current_dir != "/":
35+
if any(os.path.exists(os.path.join(current_dir, f)) for f in self.PYTHON_FILES):
36+
self.log_dir = os.path.join(current_dir, self.EVAL_PROTOCOL_DIR)
37+
break
38+
current_dir = os.path.dirname(current_dir)
39+
40+
# get the PWD that this python process is running in
41+
self.log_dir = os.path.join(os.getcwd(), self.EVAL_PROTOCOL_DIR)
42+
43+
# create the .eval_protocol directory if it doesn't exist
44+
os.makedirs(self.log_dir, exist_ok=True)
45+
46+
# create the datasets subdirectory
47+
self.datasets_dir = os.path.join(self.log_dir, self.DATASETS_DIR)
48+
os.makedirs(self.datasets_dir, exist_ok=True)
49+
50+
# ensure that log file exists
51+
if not os.path.exists(self.jsonl_path):
52+
with open(self.jsonl_path, "w") as f:
53+
f.write("")
54+
55+
@property
56+
def current_date(self) -> str:
57+
# Use UTC timezone to be consistent across local device/locations/CI
58+
return datetime.now(timezone.utc).strftime("%Y-%m-%d")
59+
60+
@property
61+
def jsonl_path(self) -> str:
62+
return os.path.join(self.datasets_dir, f"{self.current_date}.jsonl")
63+
64+
def log(self, row: "EvaluationRow") -> None:
65+
"""Log a row, updating existing row with same ID or appending new row."""
66+
row_id = row.input_metadata.row_id
67+
68+
# Check if row with this ID already exists
69+
if os.path.exists(self.jsonl_path):
70+
with open(self.jsonl_path, "r") as f:
71+
lines = f.readlines()
72+
73+
# Find the line with matching ID
74+
for i, line in enumerate(lines):
75+
try:
76+
line_data = json.loads(line.strip())
77+
if line_data["input_metadata"]["row_id"] == row_id:
78+
# Update existing row
79+
lines[i] = row.model_dump_json(exclude_none=True) + os.linesep
80+
with open(self.jsonl_path, "w") as f:
81+
f.writelines(lines)
82+
return
83+
except json.JSONDecodeError:
84+
continue
85+
86+
# If no existing row found, append new row
87+
with open(self.jsonl_path, "a") as f:
88+
f.write(row.model_dump_json(exclude_none=True) + os.linesep)
89+
90+
def read(self, row_id: Optional[str] = None) -> List["EvaluationRow"]:
91+
"""Read rows from the JSONL file."""
92+
if not os.path.exists(self.jsonl_path):
93+
return []
94+
95+
data = load_jsonl(self.jsonl_path)
96+
rows = [EvaluationRow(**r) for r in data]
97+
98+
if row_id:
99+
# Filter by row_id if specified
100+
return [row for row in rows if row.id == row_id]
101+
else:
102+
return rows

eval_protocol/human_id/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import random
2+
import itertools
3+
from typing import Hashable
4+
from . import dictionary
5+
6+
__all__ = ["generate_id"]
7+
8+
system_random = random.SystemRandom()
9+
10+
11+
def generate_id(separator="-", seed: int | float | str | bytes | bytearray | None = None, word_count=4) -> str:
12+
"""
13+
Generate a human readable ID
14+
15+
:param separator: The string to use to separate words
16+
:param seed: The seed to use. The same seed will produce the same ID
17+
:param word_count: The number of words to use. Minimum of 3.
18+
:return: A human readable ID
19+
"""
20+
if word_count < 3:
21+
raise ValueError("word_count cannot be lower than 3")
22+
23+
random_obj = system_random
24+
if seed:
25+
random_obj = random.Random(seed)
26+
27+
parts = {dictionary.verbs: 1, dictionary.adjectives: 1, dictionary.nouns: 1}
28+
29+
for _ in range(3, word_count):
30+
parts[random_obj.choice(list(parts.keys()))] += 1
31+
32+
parts = itertools.chain.from_iterable(random_obj.sample(part, count) for part, count in parts.items())
33+
34+
return separator.join(parts)

0 commit comments

Comments
 (0)