Repository navigation
Expand file tree
/
Copy pathworld_model_sampling_evaluate.sh
More file actions
115 lines (102 loc) · 4.38 KB
/
Copy pathworld_model_sampling_evaluate.sh
File metadata and controls
115 lines (102 loc) · 4.38 KB
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
#!/usr/bin/env bash
# src/ layout: put it on PYTHONPATH (resolved from cwd, since this must be run from
# the project root -- checkpoint/metric paths are also relative to the caller's cwd)
# so `python -m <pkg>.<module>` resolves.
export PYTHONPATH="$(pwd)/src${PYTHONPATH:+:$PYTHONPATH}"
# ------------------------------------------------------------------
# USAGE INSTRUCTIONS
# ------------------------------------------------------------------
# Pass environment variables *before* the script command.
# Assumption: You are already in the project folder. No manual venv activation
# needed -- `uv run` resolves this project's own locked environment regardless of
# what else is active in the shell.
#
# Example (Standard run):
# ./world_model_sampling_evaluate.sh
#
# Example (Override game and seeds):
# GAME_NAME="goofspiel_3" SEEDS="(42, 99)" ./world_model_sampling_evaluate.sh
#
# Example (Loosen the reconstruction/reward thresholds):
# UPPER_BOUND=0.5 REWARD_THRESHOLD=0.3 ./world_model_sampling_evaluate.sh
#
# Example (More/bigger batches):
# BATCH_SIZE=4096 NUM_BATCHES=8 ./world_model_sampling_evaluate.sh
#
# Example (Process every checkpoint in each seed directory, most trained first):
# RESTORE_STEP=-1 ./world_model_sampling_evaluate.sh
# ------------------------------------------------------------------
# CONFIGURATION
# ------------------------------------------------------------------
#Game name, including the parameters.
# As provided by game.to_compact_str
: ${GAME_NAME:="leduc"}
#Root folder of the trained networks
: ${TRAINED_NETWORKS_ROOT:="trained_networks"}
#Directory name of the algorithm to evaluate
: ${ALGO_DIR:="nash_dreamer_rnad"}
#Base path passed to the python script; it appends ALGO_DIR/GAME_NAME itself
# to form base_path/algo_dir/game_dir/seed_{id}. Set explicitly to override.
: ${BASE_PATH:="$TRAINED_NETWORKS_ROOT"}
: ${SEEDS:="(42,)"}
#Saved step of the model to restore. If < 0, every checkpoint found in each
# seed directory is processed, in descending order (most trained first).
# 0 is a valid checkpoint step, not a sentinel for "process all".
: ${RESTORE_STEP:=30000}
#Trajectories sampled per batch, and number of batches per model.
: ${BATCH_SIZE:=2058}
: ${NUM_BATCHES:=4}
#Observation reconstruction upper bound; a step is an "error" if the L-inf
# distance between the real and reconstructed observation is >= 1 - UPPER_BOUND.
: ${UPPER_BOUND:=0.7}
#A step is an "error" if |real reward - reconstructed reward| > REWARD_THRESHOLD.
: ${REWARD_THRESHOLD:=0.2}
#Uniform mix into the sampling policy (0 = pure model policy).
: ${SAMPLING_EPSILON:=0.0}
#Threshold for the posterior stochastic-state sampling at the root.
: ${SAMPLE_THRESHOLD:=0.05}
#Imagined trajectory length. <= 0 derives it from game.max_trajectory_length().
: ${AC_TRAJECTORY_LEN:=0}
#RNG seed for sampling.
: ${RNG_SEED:=0}
#Directory to save results into, as OUTPUT_DIR/seed_{id}/rollout_validity.json.
# Leave empty to save directly inside each seed's own model directory instead.
: ${OUTPUT_DIR:="world_model_metrics/rollout_validity"}
#Set to any non-empty value to print per-batch progress.
: ${VERBOSE:=""}
# Debug Output
echo "------------------------------------------------"
echo "Mode: Local"
echo "Game: $GAME_NAME"
echo "Seeds: $SEEDS"
echo "Algo dir: $ALGO_DIR"
echo "Restore step: $RESTORE_STEP"
echo "Batch size: $BATCH_SIZE"
echo "Num batches: $NUM_BATCHES"
echo "Upper bound: $UPPER_BOUND"
echo "Reward threshold: $REWARD_THRESHOLD"
echo "Sampling epsilon: $SAMPLING_EPSILON"
echo "Sample threshold: $SAMPLE_THRESHOLD"
echo "AC trajectory len: $AC_TRAJECTORY_LEN"
echo "RNG seed: $RNG_SEED"
echo "Base path: $BASE_PATH"
echo "Output dir: ${OUTPUT_DIR:-<per-seed directory>}"
echo "------------------------------------------------"
args=(
--base_path "$BASE_PATH"
--seeds "$SEEDS"
--restore_step "$RESTORE_STEP"
--game_dir "$GAME_NAME"
--algo_dir "$ALGO_DIR"
--batch_size "$BATCH_SIZE"
--num_batches "$NUM_BATCHES"
--upper_bound "$UPPER_BOUND"
--reward_threshold "$REWARD_THRESHOLD"
--sampling_epsilon "$SAMPLING_EPSILON"
--sample_threshold "$SAMPLE_THRESHOLD"
--ac_trajectory_len "$AC_TRAJECTORY_LEN"
--rng_seed "$RNG_SEED"
)
[ -n "$OUTPUT_DIR" ] && args+=(--output_dir "$OUTPUT_DIR")
[ -n "$VERBOSE" ] && args+=(--verbose)
uv run python -m world_model_experiments.world_model_sampling_eval "${args[@]}"