Sequence
int64 1
25.2k
| Time
int64 1
858M
| File
stringclasses 830
values | RangeOffset
int64 0
2.21M
| RangeLength
int64 0
168k
| Text
stringlengths 1
4.7M
⌀ | Language
stringclasses 20
values | Type
stringclasses 9
values |
|---|---|---|---|---|---|---|---|
342
| 936,717
|
train_tokenizer.py
| 6,712
| 1
| null |
python
|
content
|
343
| 936,717
|
train_tokenizer.py
| 6,666
| 1
| null |
python
|
content
|
344
| 936,717
|
train_tokenizer.py
| 6,630
| 1
| null |
python
|
content
|
345
| 936,718
|
train_tokenizer.py
| 6,571
| 1
| null |
python
|
content
|
346
| 936,828
|
train_tokenizer.py
| 6,570
| 0
| null |
python
|
selection_command
|
347
| 939,326
|
train_tokenizer.py
| 6,534
| 0
| null |
python
|
selection_command
|
348
| 944,538
|
train_lam.py
| 0
| 0
|
from dataclasses import dataclass\nimport os\nimport time\n\nimport einops\nfrom flax.training import orbax_utils\nfrom flax.training.train_state import TrainState\nfrom jax.sharding import Mesh, PartitionSpec, NamedSharding\nfrom jax.experimental.mesh_utils import create_device_mesh\nimport optax\nimport orbax\nfrom orbax.checkpoint import PyTreeCheckpointer\nimport numpy as np\nimport dm_pix as pix\nimport jax\nimport jax.numpy as jnp\nimport tyro\nimport wandb\n\nfrom models.lam import LatentActionModel\nfrom utils.dataloader import get_dataloader\n\nts = int(time.time())\n\n\n@dataclass\nclass Args:\n # Experiment\n num_steps: int = 200_000\n seed: int = 0\n seq_len: int = 16\n image_channels: int = 3\n image_height: int = 90\n image_width: int = 160\n data_dir: str = "data_tfrecords/coinrun"\n checkpoint: str = ""\n # Optimization\n batch_size: int = 36\n vq_beta: float = 0.25\n min_lr: float = 3e-6\n max_lr: float = 3e-5\n warmup_steps: int = 5000\n vq_reset_thresh: int = 50\n # LAM\n model_dim: int = 512\n latent_dim: int = 32\n num_latents: int = 6\n patch_size: int = 16\n num_blocks: int = 8\n num_heads: int = 8\n dropout: float = 0.0\n codebook_dropout: float = 0.0\n # Logging\n log: bool = False\n entity: str = ""\n project: str = ""\n log_interval: int = 5\n log_image_interval: int = 250\n ckpt_dir: str = ""\n log_checkpoint_interval: int = 10000\n\n\nargs = tyro.cli(Args)\n\n\ndef lam_loss_fn(params, state, inputs):\n # --- Compute loss ---\n outputs = state.apply_fn(\n params, inputs, training=True, rngs={"dropout": inputs["rng"]}\n )\n gt_future_frames = inputs["videos"][:, 1:]\n mse = jnp.square(gt_future_frames - outputs["recon"]).mean()\n q_loss = jnp.square(jax.lax.stop_gradient(outputs["emb"]) - outputs["z"]).mean()\n commitment_loss = jnp.square(\n outputs["emb"] - jax.lax.stop_gradient(outputs["z"])\n ).mean()\n loss = mse + q_loss + args.vq_beta * commitment_loss\n\n # --- Compute validation metrics ---\n gt = gt_future_frames.clip(0, 1).reshape(-1, *gt_future_frames.shape[2:])\n recon = outputs["recon"].clip(0, 1).reshape(-1, *outputs["recon"].shape[2:])\n psnr = pix.psnr(gt, recon).mean()\n ssim = pix.ssim(gt, recon).mean()\n count_fn = jax.vmap(lambda i: (outputs["indices"] == i).sum())\n index_counts = count_fn(jnp.arange(args.num_latents))\n metrics = dict(\n loss=loss,\n mse=mse,\n q_loss=q_loss,\n commitment_loss=commitment_loss,\n psnr=psnr,\n ssim=ssim,\n codebook_usage=(index_counts != 0).mean(),\n )\n return loss, (outputs["recon"], index_counts, metrics)\n\n\n@jax.jit\ndef train_step(state, inputs, action_last_active):\n # --- Update model ---\n rng, inputs["rng"] = jax.random.split(inputs["rng"])\n grad_fn = jax.value_and_grad(lam_loss_fn, has_aux=True, allow_int=True)\n (loss, (recon, idx_counts, metrics)), grads = grad_fn(state.params, state, inputs)\n state = state.apply_gradients(grads=grads)\n\n # --- Reset inactive latent actions ---\n codebook = state.params["params"]["vq"]["codebook"]\n num_codes = len(codebook)\n active_codes = idx_counts != 0.0\n action_last_active = jnp.where(active_codes, 0, action_last_active + 1)\n p_code = active_codes / active_codes.sum()\n reset_idxs = jax.random.choice(rng, num_codes, shape=(num_codes,), p=p_code)\n do_reset = action_last_active >= args.vq_reset_thresh\n new_codebook = jnp.where(\n jnp.expand_dims(do_reset, -1), codebook[reset_idxs], codebook\n )\n state.params["params"]["vq"]["codebook"] = new_codebook\n action_last_active = jnp.where(do_reset, 0, action_last_active)\n return state, loss, recon, action_last_active, metrics\n\n\nif __name__ == "__main__":\n jax.distributed.initialize()\n num_devices = jax.device_count()\n if num_devices == 0:\n raise ValueError("No JAX devices found.")\n print(f"Running on {num_devices} devices.")\n\n if args.batch_size % num_devices != 0:\n raise ValueError(\n f"Global batch size {args.batch_size} must be divisible by "\n f"number of devices {num_devices}."\n )\n\n per_device_batch_size_for_init = args.batch_size // num_devices\n\n rng = jax.random.PRNGKey(args.seed)\n if args.log and jax.process_index() == 0:\n wandb.init(entity=args.entity, project=args.project, group="debug", config=args)\n\n # --- Initialize model ---\n lam = LatentActionModel(\n in_dim=args.image_channels,\n model_dim=args.model_dim,\n latent_dim=args.latent_dim,\n num_latents=args.num_latents,\n patch_size=args.patch_size,\n num_blocks=args.num_blocks,\n num_heads=args.num_heads,\n dropout=args.dropout,\n codebook_dropout=args.codebook_dropout,\n )\n # Track when each action was last sampled\n action_last_active = jnp.zeros(args.num_latents)\n image_shape = (args.image_height, args.image_width, args.image_channels)\n rng, _rng = jax.random.split(rng)\n inputs = dict(\n videos=jnp.zeros(\n (per_device_batch_size_for_init, args.seq_len, *image_shape),\n dtype=jnp.float32,\n ),\n rng=_rng,\n )\n rng, _rng = jax.random.split(rng)\n init_params = lam.init(_rng, inputs)\n\n # --- Initialize optimizer ---\n lr_schedule = optax.warmup_cosine_decay_schedule(\n args.min_lr, args.max_lr, args.warmup_steps, args.num_steps\n )\n tx = optax.adamw(learning_rate=lr_schedule, b1=0.9, b2=0.9, weight_decay=1e-4)\n train_state = TrainState.create(apply_fn=lam.apply, params=init_params, tx=tx)\n\n # FIXME: switch to create_hybrid_device_mesh for runs spanning multiple nodes\n device_mesh_arr = create_device_mesh((num_devices,))\n mesh = Mesh(devices=device_mesh_arr, axis_names=("data",))\n\n replicated_sharding = NamedSharding(mesh, PartitionSpec())\n train_state = jax.device_put(train_state, replicated_sharding)\n action_last_active = jax.device_put(action_last_active, replicated_sharding)\n\n # --- Load checkpoint ---\n step = 0\n if args.checkpoint:\n restore_target = {"model": train_state}\n restore_args = orbax_utils.restore_args_from_target(restore_target)\n train_state.params["params"].update(\n PyTreeCheckpointer()\n .restore(args.checkpoint, item=restore_target, restore_args=restore_args)[\n "model"\n ]\n .params["params"]\n )\n # Assume checkpoint is of the form tokenizer_<timestamp>_<step>\n step += int(args.checkpoint.split("_")[-1])\n\n # --- TRAIN LOOP ---\n tfrecord_files = [\n os.path.join(args.data_dir, x)\n for x in os.listdir(args.data_dir)\n if x.endswith(".tfrecord")\n ]\n dataloader = get_dataloader(\n # NOTE: We deliberately pass the global batch size\n # The dataloader shards the dataset across all processes\n tfrecord_files,\n args.seq_len,\n args.batch_size,\n *image_shape,\n )\n print(f"Starting training from step {step}...")\n while step < args.num_steps:\n # for videos in dataloader:\n npy_path = "overfit_dir/single_sample_corner.npy"\n videos = np.load(npy_path)\n print("batch shape: ", videos.shape)\n while(True):\n # --- Train step ---\n rng, _rng = jax.random.split(rng)\n\n videos_sharding = NamedSharding(\n mesh, PartitionSpec("data", None, None, None, None)\n )\n videos = jax.make_array_from_process_local_data(videos_sharding, videos)\n\n inputs = dict(videos=videos, rng=_rng)\n start_time = time.time()\n train_state, loss, recon, action_last_active, metrics = train_step(\n train_state, inputs, action_last_active\n )\n elapsed_time = (time.time() - start_time) * 1000\n print(f"Step {step}, loss: {loss}, step time: {elapsed_time}ms")\n step += 1\n\n # --- Logging ---\n if args.log:\n if step % args.log_interval == 0 and jax.process_index() == 0:\n wandb.log(\n {\n "loss": loss,\n "step": step,\n "step_time_ms": elapsed_time,\n **metrics,\n }\n )\n if step % args.log_image_interval == 0:\n gt_seq = inputs["videos"][0][1:]\n recon_seq = recon[0].clip(0, 1)\n comparison_seq = jnp.concatenate((gt_seq, recon_seq), axis=1)\n comparison_seq = einops.rearrange(\n comparison_seq * 255, "t h w c -> h (t w) c"\n )\n if jax.process_index() == 0:\n log_images = dict(\n image=wandb.Image(np.asarray(gt_seq[0])),\n recon=wandb.Image(np.asarray(recon_seq[0])),\n true_vs_recon=wandb.Image(\n np.asarray(comparison_seq.astype(np.uint8))\n ),\n )\n wandb.log(log_images)\n if step % args.log_checkpoint_interval == 0:\n ckpt = {"model": train_state}\n orbax_checkpointer = orbax.checkpoint.PyTreeCheckpointer()\n save_args = orbax_utils.save_args_from_target(ckpt)\n orbax_checkpointer.save(\n os.path.join(os.getcwd(), args.ckpt_dir, f"lam_{ts}_{step}"),\n ckpt,\n save_args=save_args,\n )\n if step >= args.num_steps:\n break\n
|
python
|
tab
|
349
| 945,719
|
train_lam.py
| 9,776
| 0
| null |
python
|
selection_command
|
350
| 946,295
|
train_lam.py
| 9,754
| 0
| null |
python
|
selection_command
|
351
| 946,786
|
train_lam.py
| 9,715
| 0
| null |
python
|
selection_command
|
352
| 946,819
|
train_lam.py
| 9,697
| 0
| null |
python
|
selection_command
|
353
| 946,853
|
train_lam.py
| 9,656
| 0
| null |
python
|
selection_command
|
354
| 946,887
|
train_lam.py
| 9,630
| 0
| null |
python
|
selection_command
|
355
| 946,921
|
train_lam.py
| 9,548
| 0
| null |
python
|
selection_command
|
356
| 946,956
|
train_lam.py
| 9,507
| 0
| null |
python
|
selection_command
|
357
| 946,990
|
train_lam.py
| 9,439
| 0
| null |
python
|
selection_command
|
358
| 947,024
|
train_lam.py
| 9,364
| 0
| null |
python
|
selection_command
|
359
| 947,059
|
train_lam.py
| 9,318
| 0
| null |
python
|
selection_command
|
360
| 947,060
|
train_lam.py
| 9,261
| 0
| null |
python
|
selection_command
|
361
| 947,094
|
train_lam.py
| 9,215
| 0
| null |
python
|
selection_command
|
362
| 947,129
|
train_lam.py
| 9,189
| 0
| null |
python
|
selection_command
|
363
| 947,163
|
train_lam.py
| 9,158
| 0
| null |
python
|
selection_command
|
364
| 947,198
|
train_lam.py
| 9,082
| 0
| null |
python
|
selection_command
|
365
| 947,232
|
train_lam.py
| 9,027
| 0
| null |
python
|
selection_command
|
366
| 947,268
|
train_lam.py
| 8,954
| 0
| null |
python
|
selection_command
|
367
| 947,307
|
train_lam.py
| 8,884
| 0
| null |
python
|
selection_command
|
368
| 947,352
|
train_lam.py
| 8,841
| 0
| null |
python
|
selection_command
|
369
| 947,386
|
train_lam.py
| 8,792
| 0
| null |
python
|
selection_command
|
370
| 947,422
|
train_lam.py
| 8,770
| 0
| null |
python
|
selection_command
|
371
| 947,423
|
train_lam.py
| 8,701
| 0
| null |
python
|
selection_command
|
372
| 947,458
|
train_lam.py
| 8,646
| 0
| null |
python
|
selection_command
|
373
| 947,458
|
train_lam.py
| 8,564
| 0
| null |
python
|
selection_command
|
374
| 947,491
|
train_lam.py
| 8,512
| 0
| null |
python
|
selection_command
|
375
| 947,525
|
train_lam.py
| 8,459
| 0
| null |
python
|
selection_command
|
376
| 947,560
|
train_lam.py
| 8,403
| 0
| null |
python
|
selection_command
|
377
| 947,594
|
train_lam.py
| 8,381
| 0
| null |
python
|
selection_command
|
378
| 947,629
|
train_lam.py
| 8,355
| 0
| null |
python
|
selection_command
|
379
| 947,664
|
train_lam.py
| 8,316
| 0
| null |
python
|
selection_command
|
380
| 947,700
|
train_lam.py
| 8,258
| 0
| null |
python
|
selection_command
|
381
| 947,732
|
train_lam.py
| 8,216
| 0
| null |
python
|
selection_command
|
382
| 947,732
|
train_lam.py
| 8,174
| 0
| null |
python
|
selection_command
|
383
| 947,766
|
train_lam.py
| 8,148
| 0
| null |
python
|
selection_command
|
384
| 947,798
|
train_lam.py
| 8,117
| 0
| null |
python
|
selection_command
|
385
| 947,830
|
train_lam.py
| 8,038
| 0
| null |
python
|
selection_command
|
386
| 947,874
|
train_lam.py
| 8,013
| 0
| null |
python
|
selection_command
|
387
| 947,902
|
train_lam.py
| 7,983
| 0
| null |
python
|
selection_command
|
388
| 947,903
|
train_lam.py
| 7,982
| 0
| null |
python
|
selection_command
|
389
| 947,938
|
train_lam.py
| 7,960
| 0
| null |
python
|
selection_command
|
390
| 947,972
|
train_lam.py
| 7,883
| 0
| null |
python
|
selection_command
|
391
| 948,006
|
train_lam.py
| 7,822
| 0
| null |
python
|
selection_command
|
392
| 948,041
|
train_lam.py
| 7,808
| 0
| null |
python
|
selection_command
|
393
| 948,075
|
train_lam.py
| 7,752
| 0
| null |
python
|
selection_command
|
394
| 948,117
|
train_lam.py
| 7,672
| 0
| null |
python
|
selection_command
|
395
| 948,118
|
train_lam.py
| 7,635
| 0
| null |
python
|
selection_command
|
396
| 948,160
|
train_lam.py
| 7,584
| 0
| null |
python
|
selection_command
|
397
| 948,202
|
train_lam.py
| 7,583
| 0
| null |
python
|
selection_command
|
398
| 948,203
|
train_lam.py
| 7,498
| 0
| null |
python
|
selection_command
|
399
| 948,245
|
train_lam.py
| 7,484
| 0
| null |
python
|
selection_command
|
400
| 948,285
|
train_lam.py
| 7,416
| 0
| null |
python
|
selection_command
|
401
| 948,294
|
train_lam.py
| 7,371
| 0
| null |
python
|
selection_command
|
402
| 948,337
|
train_lam.py
| 7,370
| 0
| null |
python
|
selection_command
|
403
| 948,387
|
train_lam.py
| 7,324
| 0
| null |
python
|
selection_command
|
404
| 948,388
|
train_lam.py
| 7,291
| 0
| null |
python
|
selection_command
|
405
| 948,434
|
train_lam.py
| 7,270
| 0
| null |
python
|
selection_command
|
406
| 948,485
|
train_lam.py
| 7,225
| 0
| null |
python
|
selection_command
|
407
| 948,485
|
train_lam.py
| 7,190
| 0
| null |
python
|
selection_command
|
408
| 948,539
|
train_lam.py
| 7,132
| 0
| null |
python
|
selection_command
|
409
| 948,540
|
train_lam.py
| 7,096
| 0
| null |
python
|
selection_command
|
410
| 948,596
|
train_lam.py
| 7,063
| 0
| null |
python
|
selection_command
|
411
| 948,597
|
train_lam.py
| 7,011
| 0
| null |
python
|
selection_command
|
412
| 948,638
|
train_lam.py
| 7,005
| 0
| null |
python
|
selection_command
|
413
| 948,689
|
train_lam.py
| 6,983
| 0
| null |
python
|
selection_command
|
414
| 948,689
|
train_lam.py
| 6,958
| 0
| null |
python
|
selection_command
|
415
| 948,726
|
train_lam.py
| 6,936
| 0
| null |
python
|
selection_command
|
416
| 949,153
|
train_lam.py
| 6,912
| 0
| null |
python
|
selection_command
|
417
| 950,097
|
train_lam.py
| 6,847
| 0
| null |
python
|
selection_command
|
418
| 950,280
|
train_lam.py
| 6,912
| 0
| null |
python
|
selection_command
|
419
| 950,425
|
train_lam.py
| 6,936
| 0
| null |
python
|
selection_command
|
420
| 950,573
|
train_lam.py
| 6,958
| 0
| null |
python
|
selection_command
|
421
| 950,741
|
train_lam.py
| 6,983
| 0
| null |
python
|
selection_command
|
422
| 950,891
|
train_lam.py
| 7,005
| 0
| null |
python
|
selection_command
|
423
| 951,039
|
train_lam.py
| 7,011
| 0
| null |
python
|
selection_command
|
424
| 951,202
|
train_lam.py
| 7,063
| 0
| null |
python
|
selection_command
|
425
| 951,352
|
train_lam.py
| 7,096
| 0
| null |
python
|
selection_command
|
426
| 952,966
|
train_tokenizer.py
| 0
| 0
| null |
python
|
tab
|
427
| 958,909
|
scripts/train_tokenizer_overfit_sample.sbatch
| 0
| 0
|
#!/bin/bash\n#SBATCH --nodes=1\n#SBATCH --ntasks-per-node=1\n#SBATCH --time=01:00:00\n#SBATCH --cpus-per-task=5\n#SBATCH --gres=gpu:1,VRAM:24G\n#SBATCH --mem=50G\n#SBATCH --output=logs/logs_training/%x_%j.log\n#SBATCH --error=logs/logs_training/%x_%j.log\n#SBATCH --job-name=train_tokenizer_minecraft_overfit_sample\n\n# Log the sbatch script\ncat $0\n\ntf_records_dir="/storage/user/mahajanm/Projects/world-modeling/knoms_tfrecords_500/"\nws_dir='/storage/user/mahajanm/Projects/world-modeling'\njob_name=$SLURM_JOB_NAME\nslurm_job_id=$SLURM_JOB_ID\n\nCHECKPOINT_DIR=$ws_dir/checkpoints/$job_name_$slurm_job_id\nmkdir -p $CHECKPOINT_DIR\n\nenv | grep SLURM\n\nSLURM_STEP_NODELIST=$SLURM_NODELIST python train_tokenizer.py \\n --ckpt_dir $CHECKPOINT_DIR \\n --batch_size=1 \\n --min_lr=4.3e-5 \\n --max_lr=4.3e-5 \\n --log_image_interval=3 \\n --log \\n --entity instant-uv \\n --project jafar \\n --data_dir $tf_records_dir\n
|
shellscript
|
tab
|
428
| 960,545
|
scripts/train_tokenizer_overfit_sample.sbatch
| 74
| 0
| null |
shellscript
|
selection_mouse
|
429
| 961,781
|
scripts/train_tokenizer_overfit_sample.sbatch
| 74
| 1
|
5
|
shellscript
|
content
|
430
| 989,565
|
scripts/train_lam_overfit_sample.sh
| 0
| 0
|
#!/usr/bin/env bash\n\n# Log the sbatch script\ncat $0\n\ntf_records_dir="/storage/user/mahajanm/Projects/world-modeling/knoms_tfrecords_500/"\nws_dir='/storage/user/mahajanm/Projects/world-modeling'\njob_name=$SLURM_JOB_NAME\nslurm_job_id=$SLURM_JOB_ID\n\nCHECKPOINT_DIR=$ws_dir/checkpoints/$job_name_$slurm_job_id\nmkdir -p $CHECKPOINT_DIR\n\nenv | grep SLURM\n\nSLURM_STEP_NODELIST=$SLURM_NODELIST python train_lam.py \\n --ckpt_dir $CHECKPOINT_DIR \\n --batch_size=1 \\n --min_lr=5e-7 \\n --max_lr=5e-6 \\n --warmup_steps=125 \\n --log_image_interval=3 \\n --log \\n --entity instant-uv \\n --project jafar \\n --data_dir $tf_records_dir\n
|
shellscript
|
tab
|
431
| 991,954
|
scripts/train_tokenizer_overfit_sample.sbatch
| 0
| 0
| null |
shellscript
|
tab
|
432
| 992,496
|
scripts/train_tokenizer_overfit_sample.sbatch
| 46
| 0
| null |
shellscript
|
selection_command
|
433
| 997,970
|
scripts/train_lam_overfit_sample.sh
| 0
| 0
| null |
shellscript
|
tab
|
434
| 1,005,880
|
scripts/train_lam_overfit_sample.sbatch
| 0
| 0
|
#!/bin/bash\n#SBATCH --nodes=1\n#SBATCH --ntasks-per-node=1\n#SBATCH --time=01:00:00\n#SBATCH --cpus-per-task=5\n#SBATCH --gres=gpu:1,VRAM:24G\n#SBATCH --mem=50G\n#SBATCH --output=logs/logs_training/%x_%j.log\n#SBATCH --error=logs/logs_training/%x_%j.log\n#SBATCH --job-name=train_lam_minecraft_overfit_sample\n\n# Log the sbatch script\ncat $0\n\ntf_records_dir="/storage/user/mahajanm/Projects/world-modeling/knoms_tfrecords_500/"\nws_dir='/storage/user/mahajanm/Projects/world-modeling'\njob_name=$SLURM_JOB_NAME\nslurm_job_id=$SLURM_JOB_ID\n\nCHECKPOINT_DIR=$ws_dir/checkpoints/$job_name_$slurm_job_id\nmkdir -p $CHECKPOINT_DIR\n\nenv | grep SLURM\n\nSLURM_STEP_NODELIST=$SLURM_NODELIST python train_lam.py \\n --ckpt_dir $CHECKPOINT_DIR \\n --batch_size=1 \\n --min_lr=5e-7 \\n --max_lr=5e-6 \\n --warmup_steps=125 \\n --log_image_interval=3 \\n --log \\n --entity instant-uv \\n --project jafar \\n --data_dir $tf_records_dir\n
|
shellscript
|
tab
|
435
| 1,007,690
|
scripts/train_lam_overfit_sample.sbatch
| 74
| 0
| null |
shellscript
|
selection_mouse
|
436
| 1,008,666
|
scripts/train_lam_overfit_sample.sbatch
| 74
| 1
|
5
|
shellscript
|
content
|
437
| 1,018,055
|
utils/dataloader_new.py
| 0
| 0
| null |
python
|
tab
|
438
| 1,018,641
|
utils/dataloader_new.py
| 3,091
| 0
| null |
python
|
selection_mouse
|
439
| 1,018,642
|
utils/dataloader_new.py
| 3,090
| 0
| null |
python
|
selection_command
|
440
| 1,026,471
|
utils/dataloader_new.py
| 3,592
| 0
| null |
python
|
selection_mouse
|
441
| 1,026,488
|
utils/dataloader_new.py
| 3,591
| 0
| null |
python
|
selection_command
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.