p-doom/crowd-code-dataset-0.2 huggingface dataset:
[tab] slurm/dev/franz/berlin/coinrun/sample/maskgit/sample_mila_submission.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=4
#SBATCH --time=01:00:00
#SBATCH --partition=accelerated
#SBATCH --cpus-per-task=5
#SBATCH --gres=gpu:4
#SBATCH --output=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/dynamics_sample/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/dynamics_sample/%x_%j.log
#SBATCH --job-name=coinrun_sample_maskgit_mila_submission

# Activate virtual environment
source .venv/bin/activate

array_records_dir="/fast/project/HFMI_SynergyUnit/jafar_ws/data/coinrun/array_records_500m_seed_w_increment/val"
CHECKPOINT_PATH=""


echo "Sampling from checkpoint: $CHECKPOINT_PATH"

srun python jasmine/sample.py \
    --checkpoint $CHECKPOINT_PATH \
    --data_dir=$array_records_dir \
    --seq_len=16 \
    --batch_size=4 \
    --patch_size=16 \
    --start_frame=4 \
    --image_height=64 \
    --image_width=64 \
    --dyna_type=maskgit
[content] slurm/dev/franz/berlin/atari/tokenizer.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --gres=gpu:1
#SBATCH --time=24:00:00
#SBATCH --cpus-per-task=8
#SBATCH --output=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/tokenizer/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/tokenizer/%x_%j.log
#SBATCH --job-name=tokenizer_coinrun_mila_submission
#SBATCH --requeue
#SBATCH --signal=b:usr1@300 # 5 min before timeout

# --- signal trap to requeue job before timeout ---
requeue_job() {
    echo "[$(date)] caught sigusr1 (timeout warning), requeueing slurm job $SLURM_JOB_ID..."
    # optional: trigger checkpoint saving here
    # e.g., touch $checkpoint_dir/requeue_trigger
    scontrol requeue $SLURM_JOB_ID
    exit 0
}

trap requeue_job sigusr1

# set checkpoint flag based on restart count
restart_count=$(scontrol show job $SLURM_JOB_ID | grep -o 'Restarts=[0-9]*' | cut -d'=' -f2)

if [ $restart_count -eq 0 ]; then
    restore_ckpt_flag="--no-restore-ckpt"
else
    restore_ckpt_flag="--restore-ckpt"
fi

# Log the sbatch script
cat $0

source .venv/bin/activate

job_name=$SLURM_JOB_NAME
slurm_job_id=$SLURM_JOB_ID

tags="coinrun tokenizer 50m_dataset mila_submission unicorn"

array_records_dir="/fast/project/HFMI_SynergyUnit/jafar_ws/data/coinrun/array_records_500m_seed_w_increment"
CHECKPOINT_DIR="/fast/project/HFMI_SynergyUnit/jafar_ws/checkpoints/coinrun/tokenizer/${job_name}_${slurm_job_id}"
mkdir -p $CHECKPOINT_DIR

env | grep SLURM

current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "prepend-action-maskgit" ]; then
    echo "This script must be run from the prepend-action-maskgit branch. Current branch is $current_branch. Exiting."
    exit 1
fi

srun python jasmine/train_tokenizer.py \
    --patch_size=16 \
    --save_ckpt \
    $restore_ckpt_flag \
    --wandb_id $SLURM_JOB_ID \
    --ckpt_dir $CHECKPOINT_DIR \
    --name="${job_name}_${slurm_job_id}" \
    --tags $tags \
    --entity instant-uv \
    --project jafar \
    --data_dir="${array_records_dir}/train" \
    --val_data_dir="${array_records_dir}/val" &

child_pid=$!

wait $child_pid
[tab] slurm/dev/franz/berlin/atari/alien_tokenizer.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --gres=gpu:1
#SBATCH --time=24:00:00
#SBATCH --cpus-per-task=8
#SBATCH --output=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/atari/tokenizer/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/atari/tokenizer/%x_%j.log
#SBATCH --job-name=tokenizer_atari_dev
#SBATCH --requeue
#SBATCH --signal=b:usr1@300 # 5 min before timeout

# --- signal trap to requeue job before timeout ---
requeue_job() {
    echo "[$(date)] caught sigusr1 (timeout warning), requeueing slurm job $SLURM_JOB_ID..."
    # optional: trigger checkpoint saving here
    # e.g., touch $checkpoint_dir/requeue_trigger
    scontrol requeue $SLURM_JOB_ID
    exit 0
}

trap requeue_job sigusr1

# set checkpoint flag based on restart count
restart_count=$(scontrol show job $SLURM_JOB_ID | grep -o 'Restarts=[0-9]*' | cut -d'=' -f2)

if [ $restart_count -eq 0 ]; then
    restore_ckpt_flag="--no-restore-ckpt"
else
    restore_ckpt_flag="--restore-ckpt"
fi

# Log the sbatch script
cat $0

source .venv/bin/activate

job_name=$SLURM_JOB_NAME
slurm_job_id=$SLURM_JOB_ID

tags="atari alien tokenizer dev"

array_records_dir="/fast/project/HFMI_SynergyUnit/jafar_ws/data/atari/alien"
CHECKPOINT_DIR="/fast/project/HFMI_SynergyUnit/jafar_ws/checkpoints/atari/alien/tokenizer/${job_name}_${slurm_job_id}"
mkdir -p $CHECKPOINT_DIR

env | grep SLURM

current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "prepend-action-maskgit" ]; then
    echo "This script must be run from the prepend-action-maskgit branch. Current branch is $current_branch. Exiting."
    exit 1
fi

srun python jasmine/train_tokenizer.py \
    --patch_size=16 \
    --save_ckpt \
    $restore_ckpt_flag \
    --wandb_id $SLURM_JOB_ID \
    --ckpt_dir $CHECKPOINT_DIR \
    --name="${job_name}_${slurm_job_id}" \
    --tags $tags \
    --entity instant-uv \
    --project jafar \
    --data_dir="${array_records_dir}/train" \
    --val_data_dir="${array_records_dir}/val" &

child_pid=$!

wait $child_pid
[tab] slurm/jobs/franz/berlin/coinrun/mila_submission/50M_dataset/coinrun_lam_base.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --gres=gpu:1
#SBATCH --time=24:00:00
#SBATCH --cpus-per-task=8
#SBATCH --output=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/lam/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/lam/%x_%j.log
#SBATCH --job-name=lam_coinrun_mila_submission
#SBATCH --requeue
#SBATCH --signal=b:usr1@300 # 5 min before timeout

# --- signal trap to requeue job before timeout ---
requeue_job() {
    echo "[$(date)] caught sigusr1 (timeout warning), requeueing slurm job $SLURM_JOB_ID..."
    # optional: trigger checkpoint saving here
    # e.g., touch $checkpoint_dir/requeue_trigger
    scontrol requeue $SLURM_JOB_ID
    exit 0
}

trap requeue_job sigusr1

# set checkpoint flag based on restart count
restart_count=$(scontrol show job $SLURM_JOB_ID | grep -o 'Restarts=[0-9]*' | cut -d'=' -f2)

if [ $restart_count -eq 0 ]; then
    restore_ckpt_flag="--no-restore-ckpt"
else
    restore_ckpt_flag="--restore-ckpt"
fi

# Log the sbatch script
cat $0

source .venv/bin/activate

job_name=$SLURM_JOB_NAME
slurm_job_id=$SLURM_JOB_ID

tags="coinrun lam 50m_dataset mila_submission unicorn"

array_records_dir="/fast/project/HFMI_SynergyUnit/jafar_ws/data/coinrun/array_records_500m_seed_w_increment"
CHECKPOINT_DIR="/fast/project/HFMI_SynergyUnit/jafar_ws/checkpoints/coinrun/lam/${job_name}_${slurm_job_id}"
mkdir -p $CHECKPOINT_DIR

env | grep SLURM

current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "prepend-action-maskgit" ]; then
    echo "This script must be run from the prepend-action-maskgit branch. Current branch is $current_branch. Exiting."
    exit 1
fi

srun python jasmine/train_lam.py \
    --patch_size=16 \
    --save_ckpt \
    $restore_ckpt_flag \
    --wandb_id $SLURM_JOB_ID \
    --ckpt_dir $CHECKPOINT_DIR \
    --name="${job_name}_${slurm_job_id}" \
    --tags $tags \
    --entity instant-uv \
    --project jafar \
    --data_dir="${array_records_dir}/train" \
    --val_data_dir="${array_records_dir}/val" &

child_pid=$!

wait $child_pid
[content] slurm/jobs/franz/berlin/coinrun/mila_submission/50M_dataset/coinrun_lam_base.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --gres=gpu:1
#SBATCH --time=24:00:00
#SBATCH --cpus-per-task=8
#SBATCH --output=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/lam/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/lam/%x_%j.log
#SBATCH --job-name=lam_coinrun_mila_submission
#SBATCH --requeue
#SBATCH --signal=b:usr1@300 # 5 min before timeout

# --- signal trap to requeue job before timeout ---
requeue_job() {
    echo "[$(date)] caught sigusr1 (timeout warning), requeueing slurm job $SLURM_JOB_ID..."
    # optional: trigger checkpoint saving here
    # e.g., touch $checkpoint_dir/requeue_trigger
    scontrol requeue $SLURM_JOB_ID
    exit 0
}

trap requeue_job sigusr1

# set checkpoint flag based on restart count
restart_count=$(scontrol show job $SLURM_JOB_ID | grep -o 'Restarts=[0-9]*' | cut -d'=' -f2)

if [ $restart_count -eq 0 ]; then
    restore_ckpt_flag="--no-restore-ckpt"
else
    restore_ckpt_flag="--restore-ckpt"
fi

# Log the sbatch script
cat $0

source .venv/bin/activate

job_name=$SLURM_JOB_NAME
slurm_job_id=$SLURM_JOB_ID

tags="coinrun lam 50m_dataset mila_submission unicorn"

array_records_dir="/fast/project/HFMI_SynergyUnit/jafar_ws/data/coinrun/array_records_500m_seed_w_increment"
CHECKPOINT_DIR="/fast/project/HFMI_SynergyUnit/jafar_ws/checkpoints/coinrun/lam/${job_name}_${slurm_job_id}"
mkdir -p $CHECKPOINT_DIR

env | grep SLURM

current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "prepend-action-maskgit" ]; then
    echo "This script must be run from the prepend-action-maskgit branch. Current branch is $current_branch. Exiting."
    exit 1
fi

srun python jasmine/train_lam.py \
    --patch_size=16 \
    --save_ckpt \
    $restore_ckpt_flag \
    --wandb_id $SLURM_JOB_ID \
    --ckpt_dir $CHECKPOINT_DIR \
    --name="${job_name}_${slurm_job_id}" \
    --tags $tags \
    --entity instant-uv \
    --project jafar \
    --data_dir="${array_records_dir}/train" \
    --val_data_dir="${array_records_dir}/val" &

child_pid=$!

wait $child_pid
[content] slurm/dev/franz/berlin/atari/alien_lam.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --gres=gpu:1
#SBATCH --time=24:00:00
#SBATCH --cpus-per-task=8
#SBATCH --output=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/lam/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/lam/%x_%j.log
#SBATCH --job-name=lam_coinrun_mila_submission
#SBATCH --requeue
#SBATCH --signal=b:usr1@300 # 5 min before timeout

# --- signal trap to requeue job before timeout ---
requeue_job() {
    echo "[$(date)] caught sigusr1 (timeout warning), requeueing slurm job $SLURM_JOB_ID..."
    # optional: trigger checkpoint saving here
    # e.g., touch $checkpoint_dir/requeue_trigger
    scontrol requeue $SLURM_JOB_ID
    exit 0
}

trap requeue_job sigusr1

# set checkpoint flag based on restart count
restart_count=$(scontrol show job $SLURM_JOB_ID | grep -o 'Restarts=[0-9]*' | cut -d'=' -f2)

if [ $restart_count -eq 0 ]; then
    restore_ckpt_flag="--no-restore-ckpt"
else
    restore_ckpt_flag="--restore-ckpt"
fi

# Log the sbatch script
cat $0

source .venv/bin/activate

job_name=$SLURM_JOB_NAME
slurm_job_id=$SLURM_JOB_ID

tags="coinrun lam 50m_dataset mila_submission unicorn"

array_records_dir="/fast/project/HFMI_SynergyUnit/jafar_ws/data/coinrun/array_records_500m_seed_w_increment"
CHECKPOINT_DIR="/fast/project/HFMI_SynergyUnit/jafar_ws/checkpoints/coinrun/lam/${job_name}_${slurm_job_id}"
mkdir -p $CHECKPOINT_DIR

env | grep SLURM

current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "prepend-action-maskgit" ]; then
    echo "This script must be run from the prepend-action-maskgit branch. Current branch is $current_branch. Exiting."
    exit 1
fi

srun python jasmine/train_lam.py \
    --patch_size=16 \
    --save_ckpt \
    $restore_ckpt_flag \
    --wandb_id $SLURM_JOB_ID \
    --ckpt_dir $CHECKPOINT_DIR \
    --name="${job_name}_${slurm_job_id}" \
    --tags $tags \
    --entity instant-uv \
    --project jafar \
    --data_dir="${array_records_dir}/train" \
    --val_data_dir="${array_records_dir}/val" &

child_pid=$!

wait $child_pid
[content] slurm/dev/franz/berlin/atari/alien_dynamics.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --time=24:00:00
#SBATCH --cpus-per-task=8
#SBATCH --gres=gpu:1
#SBATCH --output=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/dynamics/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/coinrun/dynamics/%x_%j.log
#SBATCH --job-name=dynamics_coinrun_mila_submission
#SBATCH --requeue
#SBATCH --signal=b:usr1@300 # 5 min before timeout

# --- signal trap to requeue job before timeout ---
requeue_job() {
    echo "[$(date)] caught sigusr1 (timeout warning), requeueing slurm job $SLURM_JOB_ID..."
    # optional: trigger checkpoint saving here
    # e.g., touch $checkpoint_dir/requeue_trigger
    scontrol requeue $SLURM_JOB_ID
    exit 0
}

trap requeue_job sigusr1

# set checkpoint flag based on restart count
restart_count=$(scontrol show job $SLURM_JOB_ID | grep -o 'Restarts=[0-9]*' | cut -d'=' -f2)

if [ $restart_count -eq 0 ]; then
    restore_ckpt_flag="--no-restore-ckpt"
else
    restore_ckpt_flag="--restore-ckpt"
fi



# Log the sbatch script
cat $0

source .venv/bin/activate

job_name=$SLURM_JOB_NAME
slurm_job_id=$SLURM_JOB_ID

tags="coinrun dynamics 50m_dataset mila_submission unicorn"

array_records_dir="/fast/project/HFMI_SynergyUnit/jafar_ws/data/coinrun/array_records_500m_seed_w_increment"
tokenizer_ckpt_dir="/fast/project/HFMI_SynergyUnit/jafar_ws/checkpoints/coinrun/tokenizer/tokenizer_coinrun_mila_submission_29949"
CHECKPOINT_DIR="/fast/project/HFMI_SynergyUnit/jafar_ws/checkpoints/coinrun/dynamics/${job_name}/${slurm_job_id}"
mkdir -p $CHECKPOINT_DIR

env | grep SLURM

current_branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$current_branch" != "prepend-action-maskgit" ]; then
    echo "This script must be run from the prepend-action-maskgit branch. Current branch is $current_branch. Exiting."
    exit 1
fi

srun python jasmine/train_dynamics.py \
    --patch_size=16 \
    --save_ckpt \
    $restore_ckpt_flag \
    --wandb_id $SLURM_JOB_ID \
    --ckpt_dir $CHECKPOINT_DIR \
    --name="${job_name}_${slurm_job_id}" \
    --tags ${tags} \
    --entity instant-uv \
    --project jafar \
    --tokenizer_checkpoint="${tokenizer_ckpt_dir}" \
    --val_data_dir="${array_records_dir}/val" \
    --data_dir="${array_records_dir}/train" &

child_pid=$!

wait $child_pid
[content] slurm/dev/franz/berlin/atari/alien_tokenizer.sh (shellscript)
array_records_dir="/fast/project/HFMI_SynergyUnit/jafar_ws/data/atari/${ENV_NAME}"
CHECKPOINT_DIR="/fast/project/HFMI_SynergyUnit/jafar_ws/checkpoints/atari/${ENV_NAME}/tokenizer/${job_name}_${slurm_job_id}"
[tab] slurm/dev/franz/berlin/atari/spawn_tokenizers.sh (shellscript)
#!/usr/bin/env bash

set -euo pipefail

# Repo root to ensure .venv activation works inside the job
REPO_ROOT="/home/franz.srambical/jafar"

# Root where Atari datasets live; override with DATA_ROOT env var if needed
DATA_ROOT="${DATA_ROOT:-/fast/project/HFMI_SynergyUnit/jafar_ws/data/atari}"

# Path to the tokenizer sbatch script
TOKENIZER_SCRIPT="${TOKENIZER_SCRIPT:-$REPO_ROOT/slurm/dev/franz/berlin/atari/alien_tokenizer.sh}"

# If env names are passed as args, use them; otherwise, discover from DATA_ROOT
if [ "$#" -gt 0 ]; then
    ENV_LIST=("$@")
else
    if [ ! -d "$DATA_ROOT" ]; then
        echo "DATA_ROOT does not exist: $DATA_ROOT" >&2
        exit 1
    fi
    # list immediate subdirectories (candidate env names)
    mapfile -t ENV_LIST < <(find "$DATA_ROOT" -mindepth 1 -maxdepth 1 -type d -printf '%f
' | sort)
fi

echo "Submitting tokenizer jobs for environments: ${ENV_LIST[*]}"

for env in "${ENV_LIST[@]}"; do
    env_dir="$DATA_ROOT/$env"
    # require train and val splits to exist
    if [ ! -d "$env_dir/train" ] || [ ! -d "$env_dir/val" ]; then
        echo "Skipping $env (missing train/val under $env_dir)"
        continue
    fi

    job_name="tokenizer_atari_${env}_dev"

    # Submit job; ensure job runs from repo root so .venv resolves
    job_id=$(sbatch --parsable \
        --job-name="$job_name" \
        --chdir="$REPO_ROOT" \
        --export=ALL,ENV_NAME="$env" \
        "$TOKENIZER_SCRIPT")

    echo "Submitted $job_name (ENV_NAME=$env) as job $job_id"
done
[content] slurm/dev/franz/berlin/atari/alien_tokenizer.sh (shellscript)
# Require ENV_NAME to be provided via sbatch --export=ENV_NAME=...
if [ -z "${ENV_NAME:-}" ]; then
    echo "ENV_NAME must be provided (e.g., sbatch --export=ALL,ENV_NAME=alien $0)" >&2
    exit 2
fi

tags="atari ${ENV_NAME} tokenizer dev"
[tab] slurm/dev/franz/berlin/atari/spawn_lams.sh (shellscript)
#!/usr/bin/env bash

set -euo pipefail

REPO_ROOT="/home/franz.srambical/jafar"

DATA_ROOT="${DATA_ROOT:-/fast/project/HFMI_SynergyUnit/jafar_ws/data/atari}"

LAM_SCRIPT="${LAM_SCRIPT:-$REPO_ROOT/slurm/dev/franz/berlin/atari/alien_lam.sh}"

if [ "$#" -gt 0 ]; then
    ENV_LIST=("$@")
else
    if [ ! -d "$DATA_ROOT" ]; then
        echo "DATA_ROOT does not exist: $DATA_ROOT" >&2
        exit 1
    fi
    mapfile -t ENV_LIST < <(find "$DATA_ROOT" -mindepth 1 -maxdepth 1 -type d -printf '%f
' | sort)
fi

echo "Submitting LAM jobs for environments: ${ENV_LIST[*]}"

for env in "${ENV_LIST[@]}"; do
    env_dir="$DATA_ROOT/$env"
    if [ ! -d "$env_dir/train" ] || [ ! -d "$env_dir/val" ]; then
        echo "Skipping $env (missing train/val under $env_dir)"
        continue
    fi

    job_name="lam_atari_${env}_dev"

    job_id=$(sbatch --parsable \
        --job-name="$job_name" \
        --chdir="$REPO_ROOT" \
        --export=ALL,ENV_NAME="$env" \
        "$LAM_SCRIPT")

    echo "Submitted $job_name (ENV_NAME=$env) as job $job_id"
done
[tab] slurm/dev/franz/berlin/atari/spawn_dynamics.sh (shellscript)
#!/usr/bin/env bash

set -euo pipefail

REPO_ROOT="/home/franz.srambical/jafar"

DATA_ROOT="${DATA_ROOT:-/fast/project/HFMI_SynergyUnit/jafar_ws/data/atari}"

DYNAMICS_SCRIPT="${DYNAMICS_SCRIPT:-$REPO_ROOT/slurm/dev/franz/berlin/atari/alien_dynamics.sh}"

# Optional override: TOKENIZER_CKPT_DIR points to a specific tokenizer run dir
TOKENIZER_CKPT_DIR_OPT="${TOKENIZER_CKPT_DIR:-}"

if [ "$#" -gt 0 ]; then
    ENV_LIST=("$@")
else
    if [ ! -d "$DATA_ROOT" ]; then
        echo "DATA_ROOT does not exist: $DATA_ROOT" >&2
        exit 1
    fi
    mapfile -t ENV_LIST < <(find "$DATA_ROOT" -mindepth 1 -maxdepth 1 -type d -printf '%f
' | sort)
fi

echo "Submitting Dynamics jobs for environments: ${ENV_LIST[*]}"

for env in "${ENV_LIST[@]}"; do
    env_dir="$DATA_ROOT/$env"
    if [ ! -d "$env_dir/train" ] || [ ! -d "$env_dir/val" ]; then
        echo "Skipping $env (missing train/val under $env_dir)"
        continue
    fi

    job_name="dynamics_atari_${env}_dev"

    # Determine tokenizer checkpoint directory per env
    tokenizer_ckpt_dir=""
    if [ -n "$TOKENIZER_CKPT_DIR_OPT" ]; then
        tokenizer_ckpt_dir="$TOKENIZER_CKPT_DIR_OPT"
    else
        # Heuristic: pick the most recent run under the expected tokenizer ckpt base
        base="/fast/project/HFMI_SynergyUnit/jafar_ws/checkpoints/atari/${env}/tokenizer"
        if [ -d "$base" ]; then
            # get newest directory by mtime
            latest=$(find "$base" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %p
' | sort -nr | head -n1 | awk '{print $2}')
            if [ -n "${latest:-}" ] && [ -d "$latest" ]; then
                tokenizer_ckpt_dir="$latest"
            fi
        fi
    fi

    if [ -z "$tokenizer_ckpt_dir" ]; then
        echo "Skipping $env (no TOKENIZER_CKPT_DIR provided and none found under tokenizer ckpts)"
        continue
    fi

    job_id=$(sbatch --parsable \
        --job-name="$job_name" \
        --chdir="$REPO_ROOT" \
        --export=ALL,ENV_NAME="$env",TOKENIZER_CKPT_DIR="$tokenizer_ckpt_dir" \
        "$DYNAMICS_SCRIPT")

    echo "Submitted $job_name (ENV_NAME=$env) using tokenizer ckpt $tokenizer_ckpt_dir as job $job_id"
done