Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions areal/experimental/inference_service/controller/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from areal.api.workflow_api import RolloutWorkflow
from areal.infra import workflow_context
from areal.infra.rpc.rtensor import RTensor
from areal.infra.rpc.serialization import deserialize_value
from areal.infra.utils.http import async_http_retry
from areal.utils import logging, stats_tracker
Expand Down Expand Up @@ -245,8 +246,12 @@ async def _run_online(
if not traj:
return None

if "rewards" in traj and len(traj["rewards"]) > 0:
last_reward = float(traj["rewards"][-1])
rewards_tensor = traj.get("rewards")
if isinstance(rewards_tensor, RTensor):
rewards_tensor = rewards_tensor.to_local()

if rewards_tensor is not None and len(rewards_tensor) > 0:
last_reward = float(rewards_tensor[-1])
Comment on lines +253 to +254
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If rewards_tensor is a 0-dimensional PyTorch tensor (e.g., a scalar tensor), calling len(rewards_tensor) will raise a TypeError: len() of a 0-d tensor. To make this check robust against 0-dimensional tensors, we can check if the tensor has ndim == 0 and handle it directly, or check ndim before calling len().

        if rewards_tensor is not None:
            if getattr(rewards_tensor, "ndim", None) == 0:
                last_reward = float(rewards_tensor)
            elif len(rewards_tensor) > 0:
                last_reward = float(rewards_tensor[-1])

elif (
"interactions" in traj
and traj["interactions"]
Expand Down
3 changes: 3 additions & 0 deletions areal/infra/workflow_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from areal.api.cli_args import InferenceEngineConfig
from areal.api import RolloutWorkflow
from areal.infra.rpc.rtensor import RTensor
from .async_task_runner import (
AsyncTaskRunner,
TaskQueueFullError,
Expand Down Expand Up @@ -840,6 +841,8 @@ async def _dump_trajectory(
if traj is None:
return False, "trajectory is None"

traj = RTensor.localize(traj)

dump_dir = self._get_dump_dir(is_eval)
if dump_dir is None:
return False, "dump dir is empty"
Expand Down
Loading