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
21 changes: 21 additions & 0 deletions benchmark/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021-2026 DexForce Technology Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------

from __future__ import annotations

from .runner import BenchmarkRunner

__all__ = ["BenchmarkRunner"]
15 changes: 15 additions & 0 deletions benchmark/algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021-2026 DexForce Technology Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------
24 changes: 24 additions & 0 deletions benchmark/algorithms/grpo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: grpo
config:
policy:
name: actor_only
actor:
type: mlp
network_cfg:
hidden_sizes: [256, 256]
activation: relu
algorithm:
name: grpo
cfg:
learning_rate: 0.0001
n_epochs: 10
batch_size: 8192
gamma: 0.99
clip_coef: 0.2
ent_coef: 0.01
kl_coef: 0.0
group_size: 4
eps: 1.0e-8
reset_every_rollout: true
truncate_at_first_done: true
max_grad_norm: 0.5
26 changes: 26 additions & 0 deletions benchmark/algorithms/ppo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ppo
config:
policy:
name: actor_critic
actor:
type: mlp
network_cfg:
hidden_sizes: [256, 256]
activation: relu
critic:
type: mlp
network_cfg:
hidden_sizes: [256, 256]
activation: relu
algorithm:
name: ppo
cfg:
learning_rate: 0.0001
n_epochs: 10
batch_size: 8192
gamma: 0.99
gae_lambda: 0.95
clip_coef: 0.2
ent_coef: 0.01
vf_coef: 0.5
max_grad_norm: 0.5
75 changes: 75 additions & 0 deletions benchmark/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ----------------------------------------------------------------------------
# Copyright (c) 2021-2026 DexForce Technology Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------

from __future__ import annotations

from copy import deepcopy
from pathlib import Path
from typing import Any

import yaml


BENCHMARK_ROOT = Path(__file__).resolve().parent


def load_yaml(path: str | Path) -> dict[str, Any]:
"""Load a YAML file into a dictionary."""
with Path(path).open("r", encoding="utf-8") as file:
data = yaml.safe_load(file) or {}
if not isinstance(data, dict):
raise TypeError(f"Expected mapping in YAML file {path}, got {type(data)!r}.")
return data


def deep_update(base: dict[str, Any], override: dict[str, Any]) -> dict[str, Any]:
"""Recursively merge `override` into `base` and return a new mapping."""
merged = deepcopy(base)
for key, value in override.items():
if (
key in merged
and isinstance(merged[key], dict)
and isinstance(value, dict)
):
merged[key] = deep_update(merged[key], value)
else:
merged[key] = deepcopy(value)
return merged


def load_task_spec(name: str) -> dict[str, Any]:
"""Load a benchmark task specification by name."""
return load_yaml(BENCHMARK_ROOT / "tasks" / f"{name}.yaml")


def load_algorithm_spec(name: str) -> dict[str, Any]:
"""Load a benchmark algorithm specification by name."""
return load_yaml(BENCHMARK_ROOT / "algorithms" / f"{name}.yaml")


def load_suite_spec(name: str = "default") -> dict[str, Any]:
"""Load a benchmark suite specification by name."""
return load_yaml(BENCHMARK_ROOT / "suites" / f"{name}.yaml")


__all__ = [
"BENCHMARK_ROOT",
"deep_update",
"load_algorithm_spec",
"load_suite_spec",
"load_task_spec",
"load_yaml",
]
Loading
Loading