p-doom/crowd-code-dataset-0.2 huggingface dataset:
[tab] scripts_horeka/modelsize_scaling/dynamics/model_sizes.md (markdown)
# Tokenizer model: sizes

default: 
| Model | model_dim | num_blocks | num_heads | latent_dim | num_latents | Est. Params |
|-------|-----------|------------|-----------|------------|-------------|-------------|
| default | 512 | 8 | 8 | 32 | 1024 | ~38M |

## scaling up

| Model | model_dim | num_blocks | num_heads | latent_dim | num_latents | Est. Params |
|-------|-----------|------------|-----------|------------|-------------|-------------|
| L1 | 768 | 12 | 12 | 64 | 2048 | ~80M |
| L2 | 1024 | 12 | 16 | 128 | 2048 | ~140M |
| L3 | 1152 | 16 | 16 | 128 | 4096 | ~200M |
| L4 | 896 | 16 | 14 | 96 | 4096 | ~120M |
| L5 | 1536 | 12 | 24 | 256 | 2048 | ~190M |


## tiny models
| Model | model_dim | num_blocks | num_heads | latent_dim | num_latents | Est. Params |
|-------|-----------|------------|-----------|------------|-------------|-------------|
| S1 | 128 | 2 | 2 | 8 | 128 | ~1.1M |
| S2 | 192 | 2 | 3 | 16 | 128 | ~1.7M |
| S3 | 256 | 3 | 4 | 16 | 256 | ~2.8M |
| S4 | 320 | 4 | 5 | 24 | 256 | ~4.5M |
| S5 | 384 | 4 | 6 | 32 | 512 | ~7.5M |


# Latent Action model: sizes



# Dynamics model: sizes 

| Config | dyna_dim | dyna_num_blocks | dyna_num_heads | Approx. Params |
|--------|----------|-----------------|---------------|----------------|
| 1 | 512 | 12 | 8   | ~36M  |
| 2 | 768 | 16 | 12  | ~110M |
| 3 | 1024 | 16 | 16 | ~180M |
| 4 | 1024 | 24 | 16 | ~270M |
| 5 | 1536 | 24 | 24 | ~500M |


## tiny models
| Config | dyna_dim | dyna_num_blocks | dyna_num_heads | Approx. Params |
|--------|----------|-----------------|---------------|----------------|
| A | 128 | 2 | 4 | ~1.5M |
| B | 256 | 2 | 4 | ~3.5M |
| C | 256 | 4 | 4 | ~6M   |
| D | 384 | 4 | 6 | ~12M  |
| E | 512 | 4 | 8 | ~18M  |
[content] sample.py (python)
# dataloader = get_dataloader(args.data_dir, args.seq_len, args.batch_size)
# video_batch = next(iter(dataloader))
video_batch = np.load("overfit_dir/single_sample_corner.npy")
tfrecord_files = [
    os.path.join(args.data_dir, x)
    for x in os.listdir(args.data_dir)
    if x.endswith(".tfrecord")
]
dataloader = get_dataloader(
    tfrecord_files,
    args.seq_len,
    args.batch_size,
    args.image_height,
    args.image_width,
    args.image_channels,
    seed=args.seed,
)
video_batch = next(iter(dataloader))
[content] utils/dataloader.py (python)
    parse_fn = functools.partial(
        _parse_tfrecord_fn, image_h=image_h, image_w=image_w, image_c=image_c
    )
    dataset = dataset.map(parse_fn, num_parallel_calls=num_parallel_calls)

    tf_process_fn = functools.partial(
        _tf_process_episode,
        seq_len=seq_len,
        image_h=image_h,
        image_w=image_w,
        image_c=image_c,
        seed=seed,
    )
    dataset = dataset.map(tf_process_fn, num_parallel_calls=num_parallel_calls)
[tab] scripts_horeka/overfit_batch_tiny/tester.sh (shellscript)
#!/usr/bin/env bash

module unload mpi/openmpi/5.0
module unload devel/cuda/12.4
source .venv/bin/activate

tf_records_dir=$ws_dir/knoms_tfrecords_500_shards
ws_dir='/hkfs/work/workspace/scratch/tum_ind3695-jafa_ws_shared/'

job_name="debug"
slurm_job_id="0000"

CHECKPOINT_DIR=$ws_dir/checkpoints/$job_name_$slurm_job_id
mkdir -p $CHECKPOINT_DIR

env | grep SLURM

# Use checkpoints from tokenizer/lam overfit sample runs
tokenizer_ckpt_dir=/hkfs/work/workspace/scratch/tum_ind3695-jafa_ws_shared/checkpoints/3309662/tokenizer_1751381446_14500/
lam_ckpt_dir=/hkfs/work/workspace/scratch/tum_ind3695-jafa_ws_shared/checkpoints/3309663/lam_1751381446_200000

python train_dynamics.py \
    --ckpt_dir $CHECKPOINT_DIR \
    --batch_size=12 \
    --min_lr=1e-4 \
    --max_lr=1e-4 \
    --log_image_interval=500 \
    --log \
    --log_checkpoint_interval=500 \
    --name=masklim-0-dynamics-tiny-overfit-big-lr-$slurm_job_id \
    --tags dynamics overfit tiny masklimit-0 \
    --entity instant-uv \
    --project jafar \
    --tokenizer_checkpoint=$tokenizer_ckpt_dir \
    --lam_checkpoint=$lam_ckpt_dir \
    --data_dir $tf_records_dir \
    --tokenizer_dim=384 \
    --latent_patch_dim=32 \
    --num_patch_latents=1024 \
    --patch_size=4 \
    --tokenizer_num_blocks=8 \
    --tokenizer_num_heads=8 \
    --lam_dim=384 \
    --latent_action_dim=32 \
    --num_latent_actions=6 \
    --lam_patch_size=16 \
    --lam_num_blocks=8 \
    --lam_num_heads=8 \
    --dyna_dim=128 \
    --dyna_num_blocks=2 \
    --dyna_num_heads=4 \
    --mask_limit=0.0 \
    --num_latent_actions=1
[content] train_tokenizer.py (python)
        for videos in dataloader:
        # npy_path = "overfit_dir/single_sample_corner.npy"
        # npy_path = "overfit_dir/single_batch_12_elems.npy"
        # videos = np.load(npy_path)
        # print("batch shape: ", videos.shape)
        # while(True):
            # --- Train step ---
            np.save(f"/hkfs/work/workspace/scratch/tum_ind3695-jafa_ws_shared/data/overfit_dir/single_sample/train_tokenizer_sample_{step}.npy", np.array(videos))
            step += 1
            print(f"Step {step}")
            if step > 5000:
                exit()
            continue
[content] scripts_horeka/modelsize_scaling/dynamics/model_sizes.md (markdown)
default: 
| Model | model_dim | num_blocks | num_heads | latent_dim | num_latents | Est. Params |
|-------|-----------|------------|-----------|------------|-------------|-------------|
| default | 512 | 8 | 8 | 32 | 1024 | ~38M |

## scaling up 
### (not tested yet - TODO @mihir)

| Model | model_dim | num_blocks | num_heads | latent_dim | num_latents | Est. Params |
|-------|-----------|------------|-----------|------------|-------------|-------------|
| L1 | 768 | 12 | 12 | 64 | 2048 | ~80M |
| L2 | 1024 | 12 | 16 | 128 | 2048 | ~140M |
| L3 | 1152 | 16 | 16 | 128 | 4096 | ~200M |
| L4 | 896 | 16 | 14 | 96 | 4096 | ~120M |
| L5 | 1536 | 12 | 24 | 256 | 2048 | ~190M |


## tiny models
| Model | model_dim | num_blocks | num_heads | latent_dim | num_latents | Est. Params |
|-------|-----------|------------|-----------|------------|-------------|-------------|
| S1 | 128 | 2 | 2 | 8 | 128 | ~0.6M |
| S2 | 192 | 2 | 3 | 16 | 128 | ~1.3M |
| S3 | 256 | 3 | 4 | 16 | 256 | ~3.6M |
| S4 | 320 | 4 | 5 | 24 | 256 | ~7.4M |
| S5 | 384 | 4 | 6 | 32 | 512 | ~10M |
[content] scripts_horeka/modelsize_scaling/dynamics/model_sizes.md (markdown)
| Name | model_dim | num_blocks | num_heads | latent_dim | num_latents | Est. Params |
|-----------|-----------|------------|-----------|------------|-------------|-------------|
| L1 | 768 | 12 | 12 | 64 | 12 | ~70M |
| L2 | 1024 | 12 | 16 | 64 | 12 | ~120M |
| L3 | 1024 | 16 | 16 | 64 | 12 | ~160M |
| L4 | 1280 | 16 | 16 | 64 | 12 | ~200M |
| L5 | 1536 | 12 | 16 | 64 | 12 | ~200M |
[content] scripts_horeka/modelsize_scaling/dynamics/model_sizes.md (markdown)
|--------------|-----------|------------|-----------|------------|-------------|-------------|
| XL | 1024 | 12 | 16 | 64 | 12 | ~200M |
| L | 896 | 12 | 14 | 48 | 8 | ~150M |
| M+ | 768 | 10 | 12 | 48 | 8 | ~100M |
| M | 640 | 10 | 10 | 32 | 8 | ~70M |
| Base+ | 512 | 12 | 8 | 32 | 8 | ~55M |
[content] scripts_horeka/modelsize_scaling/dynamics/model_sizes.md (markdown)
| Name | model_dim | num_blocks | num_heads | latent_dim | num_latents | Est. Params |
|--------------|-----------|------------|-----------|------------|-------------|-------------|
| XL | 1024 | 12 | 16 | 64 | 12 | ~200M |
| L | 896 | 12 | 14 | 48 | 8 | ~150M |
| M+ | 768 | 10 | 12 | 48 | 8 | ~100M |
| M | 640 | 10 | 10 | 32 | 8 | ~70M |
| Base+ | 512 | 12 | 8 | 32 | 8 | ~55M |
[content] scripts_horeka/modelsize_scaling/dynamics/model_sizes.md (markdown)
| Name | model_dim | num_blocks | num_heads | latent_dim | num_latents | Est. Params |
|--------------|-----------|------------|-----------|------------|-------------|-------------|
| XS | 128 | 2 | 2 | 8 | 4 | ~1M |
| S | 160 | 2 | 2 | 8 | 4 | ~1.5M |
| S+ | 192 | 3 | 3 | 8 | 4 | ~2.5M |
| M- | 256 | 4 | 4 | 16 | 6 | ~5M |
| M | 320 | 6 | 4 | 16 | 6 | ~10M |
[content] scripts_horeka/overfit_batch_tiny/tester.sh (shellscript)
python train_tokenizer.py \
    --ckpt_dir $CHECKPOINT_DIR \
    --batch_size=12 \
    --min_lr=1e-4 \
    --max_lr=1e-4 \
    --log_image_interval=100 \
    --log \
    --log_checkpoint_interval=500 \
    --name=tokenizer-tiny-overfit-batch-$slurm_job_id \
    --tags tokenizer overfit-batch tiny \
    --entity instant-uv \
    --project jafar \
    --data_dir $tf_records_dir \
    --model_dim 256 \
    --latent_dim 16 \
    --num_latents 256 \
    --patch_size 4 \
    --num_blocks 3 \
    --num_heads 4 \
    --codebook_dropout 0.0
[content] scripts_horeka/overfit_batch_tiny/tester.sh (shellscript)
python train_dynamics.py \
    --ckpt_dir $CHECKPOINT_DIR \
    --batch_size=12 \
    --min_lr=1e-4 \
    --max_lr=1e-4 \
    --log_image_interval=500 \
    --log \
    --log_checkpoint_interval=500 \
    --name=masklim-0-dynamics-tiny-overfit-big-lr-$slurm_job_id \
    --tags dynamics overfit tiny masklimit-0 \
    --entity instant-uv \
    --project jafar \
    --tokenizer_checkpoint=$tokenizer_ckpt_dir \
    --lam_checkpoint=$lam_ckpt_dir \
    --data_dir $tf_records_dir \
    --tokenizer_dim=384 \
    --latent_patch_dim=32 \
    --num_patch_latents=1024 \
    --patch_size=4 \
    --tokenizer_num_blocks=8 \
    --tokenizer_num_heads=8 \
    --lam_dim=384 \
    --latent_action_dim=32 \
    --num_latent_actions=6 \
    --lam_patch_size=16 \
    --lam_num_blocks=8 \
    --lam_num_heads=8 \
    --dyna_dim=128 \
    --dyna_num_blocks=2 \
    --dyna_num_heads=4 \
    --mask_limit=0.0 \
    --num_latent_actions=1
[content] scripts_horeka/overfit_batch_tiny/train_tokenizer_overfit_batch.sbatch (shellscript)
    --ckpt_dir $CHECKPOINT_DIR \
    --batch_size=12 \
    --min_lr=1e-4 \
    --max_lr=1e-4 \
    --log_image_interval=100 \
    --log \
    --log_checkpoint_interval=500 \
    --name=tokenizer-tiny-overfit-batch-$slurm_job_id \
    --tags tokenizer overfit-batch tiny \
    --entity instant-uv \
    --project jafar \
    --data_dir $tf_records_dir \
    --model_dim 256 \
    --latent_dim 16 \
    --num_latents 256 \
    --patch_size 4 \
    --num_blocks 3 \
    --num_heads 4 \
    --codebook_dropout 0.0
[content] train_lam.py (python)

        # npy_path = "overfit_dir/single_sample_corner.npy"
        npy_path = "overfit_dir/single_batch_12_elems.npy"
        videos = np.load(npy_path)
        print("batch shape: ", videos.shape)
        videos = jax.make_array_from_process_local_data(videos_sharding, videos)
[tab] scripts_horeka/overfit_batch_tiny/train_lam_overfit_batch.sbatch (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --time=15:00:00
#SBATCH --partition=accelerated
#SBATCH --cpus-per-task=5
#SBATCH --gres=gpu:1
#SBATCH --output=logs/logs_training/%x_%j.log
#SBATCH --error=logs/logs_training/%x_%j.log
#SBATCH --mail-user=mihir.mahajan2002@gmail.com
#SBATCH --job-name=train_lam_minecraft_overfit_sample
#SBATCH --mem=50G
#SBATCH --mail-type=ALL

# Log the sbatch script
cat $0

module unload mpi/openmpi/5.0
module unload devel/cuda/12.4
source .venv/bin/activate

tf_records_dir=$ws_dir/knoms_tfrecords_500_shards
ws_dir='/hkfs/work/workspace/scratch/tum_ind3695-jafa_ws_shared/'

job_name=$SLURM_JOB_NAME
slurm_job_id=$SLURM_JOB_ID

CHECKPOINT_DIR=$ws_dir/checkpoints/$job_name_$slurm_job_id
mkdir -p $CHECKPOINT_DIR

env | grep SLURM

srun python train_lam.py \
    --ckpt_dir $CHECKPOINT_DIR \
    --batch_size=12 \
    --min_lr=3e-4 \
    --max_lr=3e-4 \
    --log_image_interval=100 \
    --log \
    --log_checkpoint_interval=500 \
    --name=lam-tiny-overfit-batch-$slurm_job_id \
    --tags lam overfit-batch tiny \
    --entity instant-uv \
    --project jafar \
    --data_dir $tf_records_dir \
    --model_dim=384 \
    --latent_dim=32 \
    --num_latents=6 \
    --patch_size=16 \
    --num_blocks=8 \
    --num_heads=8 \
    --codebook_dropout=0.0 \
    --num_latents=1
[content] scripts_horeka/overfit_batch_tiny/tester.sh (shellscript)
python train_lam.py \
    --ckpt_dir $CHECKPOINT_DIR \
    --batch_size=12 \
    --min_lr=3e-4 \
    --max_lr=3e-4 \
    --log_image_interval=100 \
    --log \
    --log_checkpoint_interval=500 \
    --name=lam-tiny-overfit-batch-$slurm_job_id \
    --tags lam overfit-batch tiny \
    --entity instant-uv \
    --project jafar \
    --data_dir $tf_records_dir \
    --model_dim=192 \
    --latent_dim=8 \
    --num_latents=4 \
    --patch_size=16 \
    --num_blocks=3 \
    --num_heads=3 \
    --codebook_dropout=0.0