Skip to content

Commit

Permalink
Fixing None error in TrajectoryMetricsCallback (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza authored Sep 30, 2024
1 parent cbc83a7 commit bfd5a08
Show file tree
Hide file tree
Showing 6 changed files with 1,141 additions and 14 deletions.
8 changes: 5 additions & 3 deletions ldp/alg/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,13 @@ def __init__(
self._eval_metrics: dict[str, list[float]] = defaultdict(list)

async def after_train_step(self, trajectories: Sequence[Trajectory]) -> None:
self._train_metrics = self._train_metrics_fn(trajectories)
if self._train_metrics_fn is not None:
self._train_metrics = self._train_metrics_fn(trajectories)

async def after_eval_step(self, trajectories: Sequence[Trajectory]) -> None:
for k, v in self._eval_metrics_fn(trajectories).items():
self._eval_metrics[k].extend(v)
if self._eval_metrics_fn is not None:
for k, v in self._eval_metrics_fn(trajectories).items():
self._eval_metrics[k].extend(v)

async def after_eval_loop(self) -> None:
self._eval_metrics.clear()
Expand Down
114 changes: 114 additions & 0 deletions tests/cassettes/test_offline_trainer[False].yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
interactions:
- request:
body:
'{"messages": [{"role": "user", "content": "Write a 5 word story via print_story"}],
"model": "gpt-4o-2024-08-06", "temperature": 0.1, "tool_choice": "required",
"tools": [{"type": "function", "function": {"name": "print_story", "description":
"Print a story.", "parameters": {"type": "object", "properties": {"story": {"description":
"Story to print.", "title": "Story", "type": "string"}}, "required": ["story"]}}},
{"type": "function", "function": {"name": "cast_float", "description": "Cast
the input argument x to a float.", "parameters": {"type": "object", "properties":
{"x": {"title": "X", "type": "string"}}, "required": ["x"]}}}, {"type": "function",
"function": {"name": "cast_int", "description": "Cast the input argument x to
an integer.", "parameters": {"type": "object", "properties": {"x": {"title":
"X", "type": "number"}}, "required": ["x"]}}}]}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- "862"
content-type:
- application/json
host:
- api.openai.com
user-agent:
- AsyncOpenAI/Python 1.46.1
x-stainless-arch:
- arm64
x-stainless-async:
- async:asyncio
x-stainless-lang:
- python
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.46.1
x-stainless-raw-response:
- "true"
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.12.5
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: !!binary |
H4sIAAAAAAAAAwAAAP//dFJLi9swEL7nV4g5J4vtvNa+hX1AoRRKm8NuU4ziTGztypJWM2YbQv57
sZx1vKHVQYj59D00o+NICFA7yAQUleSidnqyun+sDNV6qmlx9+3569vy/WldHb7E3+P5HMYtw25f
sOAP1k1ha6eRlTUdXHiUjK1qvEyWyyRO0zQAtd2hbmml48nMTpIomU2i20m0OBMrqwokyMSvkRBC
HMPeRjQ7/AOZiMYflRqJZImQ9ZeEAG91WwFJpIilYRhfwMIaRtOmNo3WA4Ct1Xkhtb4Yd+s4OF/6
JLXO76Pn6UqvHp6qh5e39dT/XOs53aWLgV8nfXAh0L4xRd+fAd7XsyszIcDIOnCdV4ZzYusPV3Qh
QPqyqdFwGx2OGwjXNpBt4EdjCFm8V4ocehKEhUcmwVYYVVZ8s4ETfJI7jf51/j3olMd9Q1KfW3iu
n/qZaFs6b7d01WLYK6Ooyj1KCk9tU7rOu/UJDtB8Gic4b2vHOdtXNK1gHCedHlx+2wC9PYNsWepB
fRr9j5XvkKUKM++/WZdQmfKiEPUxwzuBDsRY53tlSvRhNGG+Lk/2s2ixTeN4CqPT6C8AAAD//wMA
7cYwG1kDAAA=
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 8cb66081dd5096a5-SJC
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Mon, 30 Sep 2024 18:46:40 GMT
Server:
- cloudflare
Set-Cookie:
- __cf_bm=zCQLeIJPbk_GUKhCu_R0cRdb0RroCx7sDaoC_7tjg6Q-1727722000-1.0.1.1-BaW8YwfEchrXQpvcuWA2LJAFxcuww9qXiKGTiohfTpWumXZMXPK3qft7A9hjacly5HtUA7bIn2.Q6_f0QVWLeQ;
path=/; expires=Mon, 30-Sep-24 19:16:40 GMT; domain=.api.openai.com; HttpOnly;
Secure; SameSite=None
- _cfuvid=h9LmHAvJykqv1v0NRUz0E5PYI7CX9B8uBWg7pX58Yd8-1727722000377-0.0.1.1-604800000;
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
alt-svc:
- h3=":443"; ma=86400
openai-organization:
- future-house-xr4tdh
openai-processing-ms:
- "584"
openai-version:
- "2020-10-01"
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
x-ratelimit-limit-requests:
- "10000"
x-ratelimit-limit-tokens:
- "30000000"
x-ratelimit-remaining-requests:
- "9999"
x-ratelimit-remaining-tokens:
- "29999973"
x-ratelimit-reset-requests:
- 6ms
x-ratelimit-reset-tokens:
- 0s
x-request-id:
- req_0efa6594a023d5700c6063f62aba3a4d
status:
code: 200
message: OK
version: 1
116 changes: 116 additions & 0 deletions tests/cassettes/test_offline_trainer[True].yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
interactions:
- request:
body:
'{"messages": [{"role": "user", "content": "Write a 5 word story via print_story"}],
"model": "gpt-4o-2024-08-06", "temperature": 0.1, "tool_choice": "required",
"tools": [{"type": "function", "function": {"name": "print_story", "description":
"Print a story.", "parameters": {"type": "object", "properties": {"story": {"description":
"Story to print.", "title": "Story", "type": "string"}}, "required": ["story"]}}},
{"type": "function", "function": {"name": "cast_float", "description": "Cast
the input argument x to a float.", "parameters": {"type": "object", "properties":
{"x": {"title": "X", "type": "string"}}, "required": ["x"]}}}, {"type": "function",
"function": {"name": "cast_int", "description": "Cast the input argument x to
an integer.", "parameters": {"type": "object", "properties": {"x": {"title":
"X", "type": "number"}}, "required": ["x"]}}}]}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- "862"
content-type:
- application/json
host:
- api.openai.com
user-agent:
- AsyncOpenAI/Python 1.50.2
x-stainless-arch:
- arm64
x-stainless-async:
- async:asyncio
x-stainless-lang:
- python
x-stainless-os:
- MacOS
x-stainless-package-version:
- 1.50.2
x-stainless-raw-response:
- "true"
x-stainless-retry-count:
- "0"
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.12.5
method: POST
uri: https://api.openai.com/v1/chat/completions
response:
body:
string: !!binary |
H4sIAAAAAAAAAwAAAP//dFJNj9MwEL33V1hzblZJWtI2tyJYUQECLQKBKIrcZJKYdWxjT3a3qvrf
UZxukq3AB8ua5/fhGZ9mjIEoIGWQ15zyxshg++a23r273TXFRuzueBR+uFcP5fu7H4ttKWDeMfTh
N+b0zLrJdWMkktCqh3OLnLBTjVbxahVHm2TtgUYXKDtaZShY6iAO42UQroMwuRBrLXJ0kLKfM8YY
O/m9i6gKfIKUhfPnSoPO8QohHS4xBlbLrgLcOeGIK4L5COZaEaoutWqlnACktcxyLuVo3K/T5Dz2
iUuZPbrtA/55MvLTq6/J8eN3Wi6+fX79Npn49dJH4wOVrcqH/kzwoZ5emTEGijeea6xQlDnS9nhF
Zwy4rdoGFXXR4bQHf20P6R6+tMohscdaOIPWMYe5RXKMNFOiqulmD2d4IXee/ev8a9Ipi2XruLy0
8FI/DzORujJWH9xVi6EUSrg6s8idf2qX0vTenY93gPbFOMFY3RjKSN+j6gSjKO71YPxtE3R9AUkT
l5P6IvwfKyuQuPAzH75Zn1CoalQIh5j+neCOjrDJSqEqtH40fr4mi8tlmBw2UbSA2Xn2FwAA//8D
AM9hDkVZAwAA
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 8cb65fbf1ea22518-SJC
Connection:
- keep-alive
Content-Encoding:
- gzip
Content-Type:
- application/json
Date:
- Mon, 30 Sep 2024 18:46:09 GMT
Server:
- cloudflare
Set-Cookie:
- __cf_bm=bE6l8Wvwax_gSA4t0X._TRnO9zR63k9z4NB1H8djrqY-1727721969-1.0.1.1-za.DJtE50nUnzEBq8DSkjye0WSbfDu1UHbbBNSddG1u6dwenOV9dJd8h10UBEJhDL_uVDuejkLB1GC_thmG7Ug;
path=/; expires=Mon, 30-Sep-24 19:16:09 GMT; domain=.api.openai.com; HttpOnly;
Secure; SameSite=None
- _cfuvid=hAowEp24hStRGLdAxQEemJyA.b_Ov.3jo7_IVqyxdp8-1727721969196-0.0.1.1-604800000;
path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
access-control-expose-headers:
- X-Request-ID
alt-svc:
- h3=":443"; ma=86400
openai-organization:
- future-house-xr4tdh
openai-processing-ms:
- "568"
openai-version:
- "2020-10-01"
strict-transport-security:
- max-age=31536000; includeSubDomains; preload
x-ratelimit-limit-requests:
- "10000"
x-ratelimit-limit-tokens:
- "30000000"
x-ratelimit-remaining-requests:
- "9999"
x-ratelimit-remaining-tokens:
- "29999973"
x-ratelimit-reset-requests:
- 6ms
x-ratelimit-reset-tokens:
- 0s
x-request-id:
- req_7d4e4685b304674b871adb9dbbfe723f
status:
code: 200
message: OK
version: 1
Loading

0 comments on commit bfd5a08

Please sign in to comment.