Spaces:
Running
Running
File size: 6,012 Bytes
75cad04 a40ca17 75cad04 a40ca17 75cad04 a40ca17 75cad04 a40ca17 5028d3c a40ca17 a2f004f a40ca17 a2f004f a40ca17 a2f004f a40ca17 a2f004f 75cad04 a40ca17 75cad04 a2f004f a40ca17 75cad04 a2f004f 75cad04 a40ca17 c67b794 75cad04 c67b794 75cad04 a40ca17 75cad04 a40ca17 75cad04 a40ca17 ba9c430 a40ca17 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
import fnmatch
import os
import random
import time
import pybullet_envs_gymnasium # noqa: F401 pylint: disable=unused-import
from datasets import load_dataset
from huggingface_hub import HfApi
from src.evaluation import evaluate
from src.logging import setup_logger
logger = setup_logger(__name__)
API = HfApi(token=os.environ.get("TOKEN"))
RESULTS_REPO = "open-rl-leaderboard/results_v2"
ALL_ENV_IDS = [
"AdventureNoFrameskip-v4",
"AirRaidNoFrameskip-v4",
"AlienNoFrameskip-v4",
"AmidarNoFrameskip-v4",
"AssaultNoFrameskip-v4",
"AsterixNoFrameskip-v4",
"AsteroidsNoFrameskip-v4",
"AtlantisNoFrameskip-v4",
"BankHeistNoFrameskip-v4",
"BattleZoneNoFrameskip-v4",
"BeamRiderNoFrameskip-v4",
"BerzerkNoFrameskip-v4",
"BowlingNoFrameskip-v4",
"BoxingNoFrameskip-v4",
"BreakoutNoFrameskip-v4",
"CarnivalNoFrameskip-v4",
"CentipedeNoFrameskip-v4",
"ChopperCommandNoFrameskip-v4",
"CrazyClimberNoFrameskip-v4",
"DefenderNoFrameskip-v4",
"DemonAttackNoFrameskip-v4",
"DoubleDunkNoFrameskip-v4",
"ElevatorActionNoFrameskip-v4",
"EnduroNoFrameskip-v4",
"FishingDerbyNoFrameskip-v4",
"FreewayNoFrameskip-v4",
"FrostbiteNoFrameskip-v4",
"GopherNoFrameskip-v4",
"GravitarNoFrameskip-v4",
"HeroNoFrameskip-v4",
"IceHockeyNoFrameskip-v4",
"JamesbondNoFrameskip-v4",
"JourneyEscapeNoFrameskip-v4",
"KangarooNoFrameskip-v4",
"KrullNoFrameskip-v4",
"KungFuMasterNoFrameskip-v4",
"MontezumaRevengeNoFrameskip-v4",
"MsPacmanNoFrameskip-v4",
"NameThisGameNoFrameskip-v4",
"PhoenixNoFrameskip-v4",
"PitfallNoFrameskip-v4",
"PongNoFrameskip-v4",
"PooyanNoFrameskip-v4",
"PrivateEyeNoFrameskip-v4",
"QbertNoFrameskip-v4",
"RiverraidNoFrameskip-v4",
"RoadRunnerNoFrameskip-v4",
"RobotankNoFrameskip-v4",
"SeaquestNoFrameskip-v4",
"SkiingNoFrameskip-v4",
"SolarisNoFrameskip-v4",
"SpaceInvadersNoFrameskip-v4",
"StarGunnerNoFrameskip-v4",
"TennisNoFrameskip-v4",
"TimePilotNoFrameskip-v4",
"TutankhamNoFrameskip-v4",
"UpNDownNoFrameskip-v4",
"VentureNoFrameskip-v4",
"VideoPinballNoFrameskip-v4",
"WizardOfWorNoFrameskip-v4",
"YarsRevengeNoFrameskip-v4",
"ZaxxonNoFrameskip-v4",
# Box2D
"BipedalWalker-v3",
"BipedalWalkerHardcore-v3",
"CarRacing-v2",
"LunarLander-v2",
"LunarLanderContinuous-v2",
# Toy text
"Blackjack-v1",
"CliffWalking-v0",
"FrozenLake-v1",
"FrozenLake8x8-v1",
# Classic control
"Acrobot-v1",
"CartPole-v1",
"MountainCar-v0",
"MountainCarContinuous-v0",
"Pendulum-v1",
# MuJoCo
"Ant-v4",
"HalfCheetah-v4",
"Hopper-v4",
"Humanoid-v4",
"HumanoidStandup-v4",
"InvertedDoublePendulum-v4",
"InvertedPendulum-v4",
"Pusher-v4",
"Reacher-v4",
"Swimmer-v4",
"Walker2d-v4",
# PyBullet
"AntBulletEnv-v0",
"HalfCheetahBulletEnv-v0",
"HopperBulletEnv-v0",
"HumanoidBulletEnv-v0",
"InvertedDoublePendulumBulletEnv-v0",
"InvertedPendulumSwingupBulletEnv-v0",
"MinitaurBulletEnv-v0",
"ReacherBulletEnv-v0",
"Walker2DBulletEnv-v0",
]
def pattern_match(patterns, source_list):
if isinstance(patterns, str):
patterns = [patterns]
env_ids = set()
for pattern in patterns:
for matching in fnmatch.filter(source_list, pattern):
env_ids.add(matching)
return sorted(list(env_ids))
def _backend_routine():
# List only the text classification models
rl_models = list(API.list_models(filter=["reinforcement-learning"]))
logger.info(f"Found {len(rl_models)} RL models")
compatible_models = []
for model in rl_models:
filenames = [sib.rfilename for sib in model.siblings]
if "agent.pt" in filenames:
compatible_models.append((model.modelId, model.sha))
logger.info(f"Found {len(compatible_models)} compatible models")
dataset = load_dataset(RESULTS_REPO, split="train", download_mode="force_redownload", verification_mode="no_checks")
evaluated_models = [("/".join([x["user_id"], x["model_id"]]), x["sha"]) for x in dataset]
pending_models = list(set(compatible_models) - set(evaluated_models))
logger.info(f"Found {len(pending_models)} pending models")
if len(pending_models) == 0:
return None
# Shuffle the dataset
random.shuffle(pending_models)
# Select a random model
repo_id, sha = pending_models.pop()
user_id, model_id = repo_id.split("/")
row = {"model_id": model_id, "user_id": user_id, "sha": sha}
# Run an evaluation on the models
model_info = API.model_info(repo_id, revision=sha)
# Extract the environment IDs from the tags (usually only one)
env_ids = pattern_match(model_info.tags, ALL_ENV_IDS)
if len(env_ids) > 0:
env_id = env_ids[0]
logger.info(f"Running evaluation on {user_id}/{model_id}")
try:
episodic_returns = evaluate(repo_id, sha, env_id)
row["status"] = "DONE"
row["env_id"] = env_id
row["episodic_returns"] = episodic_returns
except Exception as e:
logger.error(f"Error evaluating {repo_id}: {e}")
logger.exception(e)
row["status"] = "FAILED"
else:
logger.error(f"No environment found for {model_id}")
row["status"] = "FAILED"
# load the last version of the dataset
dataset = load_dataset(
RESULTS_REPO, split="train", download_mode="force_redownload", verification_mode="no_checks"
)
dataset.add_item(row)
dataset.push_to_hub(RESULTS_REPO, split="train", token=API.token)
time.sleep(60) # Sleep for 1 minute to avoid rate limiting
def backend_routine():
try:
_backend_routine()
except Exception as e:
logger.error(f"{e.__class__.__name__}: {str(e)}")
logger.exception(e)
if __name__ == "__main__":
backend_routine()
|