diff --git a/diffusion_policy/config/train_pusht_pretrained_dinov2_base.yaml b/diffusion_policy/config/train_pusht_pretrained_dinov2_base.yaml index 32fe19116..26bd9c72e 100644 --- a/diffusion_policy/config/train_pusht_pretrained_dinov2_base.yaml +++ b/diffusion_policy/config/train_pusht_pretrained_dinov2_base.yaml @@ -2,7 +2,7 @@ defaults: - _self_ - task: pusht_image -name: pusht_pretrained_dinov2_base +name: pusht_pretrained_dinov2_base_preprocessing _target_: diffusion_policy.workspace.train_diffusion_unet_image_workspace.TrainDiffusionUnetImageWorkspace task_name: ${task.name} @@ -45,6 +45,7 @@ policy: use_group_norm: False share_rgb_model: True imagenet_norm: False + rgb_model_name: facebook/dinov2-base horizon: ${horizon} n_action_steps: ${eval:'${n_action_steps}+${n_latency_steps}'} diff --git a/diffusion_policy/config/train_pusht_pretrained_dinov2_large.yaml b/diffusion_policy/config/train_pusht_pretrained_dinov2_large.yaml index fb006d701..b424444ae 100644 --- a/diffusion_policy/config/train_pusht_pretrained_dinov2_large.yaml +++ b/diffusion_policy/config/train_pusht_pretrained_dinov2_large.yaml @@ -2,7 +2,7 @@ defaults: - _self_ - task: pusht_image -name: pusht_pretrained_dinov2_large +name: pusht_pretrained_dinov2_large_preprocessing _target_: diffusion_policy.workspace.train_diffusion_unet_image_workspace.TrainDiffusionUnetImageWorkspace task_name: ${task.name} @@ -45,6 +45,7 @@ policy: use_group_norm: False share_rgb_model: True imagenet_norm: False + rgb_model_name: facebook/dinov2-large horizon: ${horizon} n_action_steps: ${eval:'${n_action_steps}+${n_latency_steps}'} diff --git a/diffusion_policy/config/train_real_pusht.yaml b/diffusion_policy/config/train_real_pusht.yaml new file mode 100644 index 000000000..226be6274 --- /dev/null +++ b/diffusion_policy/config/train_real_pusht.yaml @@ -0,0 +1,152 @@ +defaults: + - _self_ + - task: real_pusht_image + +name: real_pusht_end2end +_target_: diffusion_policy.workspace.train_diffusion_unet_image_workspace.TrainDiffusionUnetImageWorkspace + +task_name: ${task.name} +shape_meta: ${task.shape_meta} +exp_name: "default" + +horizon: 16 +n_obs_steps: 2 +n_action_steps: 8 +n_latency_steps: 0 +dataset_obs_steps: ${n_obs_steps} +past_action_visible: False +keypoint_visible_rate: 1.0 +obs_as_global_cond: True + +policy: + _target_: diffusion_policy.policy.diffusion_unet_image_policy.DiffusionUnetImagePolicy + + shape_meta: ${shape_meta} + + noise_scheduler: + _target_: diffusers.schedulers.scheduling_ddim.DDIMScheduler + num_train_timesteps: 100 + beta_start: 0.0001 + beta_end: 0.02 + # beta_schedule is important + # this is the best we found + beta_schedule: squaredcos_cap_v2 + clip_sample: True + set_alpha_to_one: True + steps_offset: 0 + prediction_type: epsilon # or sample + + obs_encoder: + _target_: diffusion_policy.model.vision.multi_image_obs_encoder.MultiImageObsEncoder + shape_meta: ${shape_meta} + rgb_model: + _target_: diffusion_policy.model.vision.model_getter.get_resnet + name: resnet18 + weights: null + resize_shape: [224,224] + crop_shape: null + random_crop: False + use_group_norm: False + share_rgb_model: True + imagenet_norm: True + + horizon: ${horizon} + n_action_steps: ${eval:'${n_action_steps}+${n_latency_steps}'} + n_obs_steps: ${n_obs_steps} + num_inference_steps: 100 + obs_as_global_cond: ${obs_as_global_cond} + # crop_shape: null + diffusion_step_embed_dim: 128 + down_dims: [512, 1024, 2048] + kernel_size: 5 + n_groups: 8 + cond_predict_scale: True + + # scheduler.step params + # predict_epsilon: True + +ema: + _target_: diffusion_policy.model.diffusion.ema_model.EMAModel + update_after_step: 0 + inv_gamma: 1.0 + power: 0.75 + min_value: 0.0 + max_value: 0.9999 + +dataloader: + batch_size: 64 + num_workers: 8 + shuffle: True + pin_memory: True + persistent_workers: True + +val_dataloader: + batch_size: 64 + num_workers: 8 + shuffle: False + pin_memory: True + persistent_workers: True + +optimizer: + _target_: torch.optim.AdamW + lr: 1.0e-4 + betas: [0.95, 0.999] + eps: 1.0e-8 + weight_decay: 1.0e-6 + +training: + device: "cuda:0" + seed: 42 + debug: False + resume: True + # optimization + lr_scheduler: cosine + lr_warmup_steps: 100 + num_epochs: 600 + gradient_accumulate_every: 1 + # EMA destroys performance when used with BatchNorm + # replace BatchNorm with GroupNorm. + use_ema: True + freeze_encoder: False + # training loop control + # in epochs + rollout_every: 50 + checkpoint_every: 50 + val_every: 1 + sample_every: 5 + # steps per epoch + max_train_steps: null + max_val_steps: null + # misc + tqdm_interval_sec: 1.0 + +logging: + project: diffusion_policy_debug + resume: True + mode: online + name: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + tags: ["${name}", "${task_name}", "${exp_name}"] + id: null + group: null + +checkpoint: + topk: + monitor_key: train_loss + mode: min + k: 5 + format_str: 'epoch={epoch:04d}-train_loss={train_loss:.3f}.ckpt' + save_last_ckpt: True + save_last_snapshot: False + +multi_run: + run_dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + wandb_name_base: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + +hydra: + job: + override_dirname: ${name} + run: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + sweep: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + subdir: ${hydra.job.num} diff --git a/diffusion_policy/config/train_real_pusht_pretrained_dinov2_base.yaml b/diffusion_policy/config/train_real_pusht_pretrained_dinov2_base.yaml new file mode 100644 index 000000000..6f1ffdd3c --- /dev/null +++ b/diffusion_policy/config/train_real_pusht_pretrained_dinov2_base.yaml @@ -0,0 +1,149 @@ +defaults: + - _self_ + - task: real_pusht_image + +name: real_pusht_dinov2_base_preprocessing +_target_: diffusion_policy.workspace.train_diffusion_unet_image_workspace.TrainDiffusionUnetImageWorkspace + +task_name: ${task.name} +shape_meta: ${task.shape_meta} +exp_name: "default" + +horizon: 16 +n_obs_steps: 2 +n_action_steps: 8 +n_latency_steps: 0 +dataset_obs_steps: ${n_obs_steps} +past_action_visible: False +keypoint_visible_rate: 1.0 +obs_as_global_cond: True + +policy: + _target_: diffusion_policy.policy.diffusion_unet_image_policy.DiffusionUnetImagePolicy + shape_meta: ${shape_meta} + noise_scheduler: + _target_: diffusers.schedulers.scheduling_ddim.DDIMScheduler + num_train_timesteps: 100 + beta_start: 0.0001 + beta_end: 0.02 + # beta_schedule is important + # this is the best we found + beta_schedule: squaredcos_cap_v2 + clip_sample: True + set_alpha_to_one: True + steps_offset: 0 + prediction_type: epsilon # or sample + + obs_encoder: + _target_: diffusion_policy.model.vision.multi_image_obs_encoder.MultiImageObsEncoder + shape_meta: ${shape_meta} + rgb_model: + _target_: diffusion_policy.model.vision.model_getter.get_dinov2 + name: facebook/dinov2-base + crop_shape: null + random_crop: False + use_group_norm: False + share_rgb_model: True + imagenet_norm: False + rgb_model_name: facebook/dinov2-base + + horizon: ${horizon} + n_action_steps: ${eval:'${n_action_steps}+${n_latency_steps}'} + n_obs_steps: ${n_obs_steps} + num_inference_steps: 100 + obs_as_global_cond: ${obs_as_global_cond} + # crop_shape: null + diffusion_step_embed_dim: 128 + down_dims: [512, 1024, 2048] + kernel_size: 5 + n_groups: 8 + cond_predict_scale: True + + # scheduler.step params + # predict_epsilon: True + +ema: + _target_: diffusion_policy.model.diffusion.ema_model.EMAModel + update_after_step: 0 + inv_gamma: 1.0 + power: 0.75 + min_value: 0.0 + max_value: 0.9999 + +dataloader: + batch_size: 64 + num_workers: 8 + shuffle: True + pin_memory: True + persistent_workers: True + +val_dataloader: + batch_size: 64 + num_workers: 8 + shuffle: False + pin_memory: True + persistent_workers: True + +optimizer: + _target_: torch.optim.AdamW + lr: 1.0e-4 + betas: [0.95, 0.999] + eps: 1.0e-8 + weight_decay: 1.0e-6 + +training: + device: "cuda:0" + seed: 42 + debug: False + resume: True + # optimization + lr_scheduler: cosine + lr_warmup_steps: 100 + num_epochs: 600 + gradient_accumulate_every: 1 + # EMA destroys performance when used with BatchNorm + # replace BatchNorm with GroupNorm. + use_ema: True + freeze_encoder: True + # training loop control + # in epochs + rollout_every: 50 + checkpoint_every: 50 + val_every: 1 + sample_every: 5 + # steps per epoch + max_train_steps: null + max_val_steps: null + # misc + tqdm_interval_sec: 1.0 + +logging: + project: diffusion_policy_debug + resume: True + mode: online + name: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + tags: ["${name}", "${task_name}", "${exp_name}"] + id: null + group: null + +checkpoint: + topk: + monitor_key: train_loss + mode: min + k: 5 + format_str: 'epoch={epoch:04d}-train_loss={train_loss:.3f}.ckpt' + save_last_ckpt: True + save_last_snapshot: False + +multi_run: + run_dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + wandb_name_base: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + +hydra: + job: + override_dirname: ${name} + run: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + sweep: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + subdir: ${hydra.job.num} diff --git a/diffusion_policy/config/train_real_pusht_pretrained_dinov2_large.yaml b/diffusion_policy/config/train_real_pusht_pretrained_dinov2_large.yaml new file mode 100644 index 000000000..7c67c8db0 --- /dev/null +++ b/diffusion_policy/config/train_real_pusht_pretrained_dinov2_large.yaml @@ -0,0 +1,149 @@ +defaults: + - _self_ + - task: real_pusht_image + +name: real_pusht_dinov2_large_preprocessing +_target_: diffusion_policy.workspace.train_diffusion_unet_image_workspace.TrainDiffusionUnetImageWorkspace + +task_name: ${task.name} +shape_meta: ${task.shape_meta} +exp_name: "default" + +horizon: 16 +n_obs_steps: 2 +n_action_steps: 8 +n_latency_steps: 0 +dataset_obs_steps: ${n_obs_steps} +past_action_visible: False +keypoint_visible_rate: 1.0 +obs_as_global_cond: True + +policy: + _target_: diffusion_policy.policy.diffusion_unet_image_policy.DiffusionUnetImagePolicy + shape_meta: ${shape_meta} + noise_scheduler: + _target_: diffusers.schedulers.scheduling_ddim.DDIMScheduler + num_train_timesteps: 100 + beta_start: 0.0001 + beta_end: 0.02 + # beta_schedule is important + # this is the best we found + beta_schedule: squaredcos_cap_v2 + clip_sample: True + set_alpha_to_one: True + steps_offset: 0 + prediction_type: epsilon # or sample + + obs_encoder: + _target_: diffusion_policy.model.vision.multi_image_obs_encoder.MultiImageObsEncoder + shape_meta: ${shape_meta} + rgb_model: + _target_: diffusion_policy.model.vision.model_getter.get_dinov2 + name: facebook/dinov2-large + crop_shape: null + random_crop: False + use_group_norm: False + share_rgb_model: True + imagenet_norm: False + rgb_model_name: facebook/dinov2-large + + horizon: ${horizon} + n_action_steps: ${eval:'${n_action_steps}+${n_latency_steps}'} + n_obs_steps: ${n_obs_steps} + num_inference_steps: 100 + obs_as_global_cond: ${obs_as_global_cond} + # crop_shape: null + diffusion_step_embed_dim: 128 + down_dims: [512, 1024, 2048] + kernel_size: 5 + n_groups: 8 + cond_predict_scale: True + + # scheduler.step params + # predict_epsilon: True + +ema: + _target_: diffusion_policy.model.diffusion.ema_model.EMAModel + update_after_step: 0 + inv_gamma: 1.0 + power: 0.75 + min_value: 0.0 + max_value: 0.9999 + +dataloader: + batch_size: 64 + num_workers: 8 + shuffle: True + pin_memory: True + persistent_workers: True + +val_dataloader: + batch_size: 64 + num_workers: 8 + shuffle: False + pin_memory: True + persistent_workers: True + +optimizer: + _target_: torch.optim.AdamW + lr: 1.0e-4 + betas: [0.95, 0.999] + eps: 1.0e-8 + weight_decay: 1.0e-6 + +training: + device: "cuda:0" + seed: 42 + debug: False + resume: True + # optimization + lr_scheduler: cosine + lr_warmup_steps: 100 + num_epochs: 600 + gradient_accumulate_every: 1 + # EMA destroys performance when used with BatchNorm + # replace BatchNorm with GroupNorm. + use_ema: True + freeze_encoder: True + # training loop control + # in epochs + rollout_every: 50 + checkpoint_every: 50 + val_every: 1 + sample_every: 5 + # steps per epoch + max_train_steps: null + max_val_steps: null + # misc + tqdm_interval_sec: 1.0 + +logging: + project: diffusion_policy_debug + resume: True + mode: online + name: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + tags: ["${name}", "${task_name}", "${exp_name}"] + id: null + group: null + +checkpoint: + topk: + monitor_key: train_loss + mode: min + k: 5 + format_str: 'epoch={epoch:04d}-train_loss={train_loss:.3f}.ckpt' + save_last_ckpt: True + save_last_snapshot: False + +multi_run: + run_dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + wandb_name_base: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + +hydra: + job: + override_dirname: ${name} + run: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + sweep: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + subdir: ${hydra.job.num} diff --git a/diffusion_policy/config/train_real_pusht_pretrained_imagenet.yaml b/diffusion_policy/config/train_real_pusht_pretrained_imagenet.yaml new file mode 100644 index 000000000..ec2b59518 --- /dev/null +++ b/diffusion_policy/config/train_real_pusht_pretrained_imagenet.yaml @@ -0,0 +1,152 @@ +defaults: + - _self_ + - task: real_pusht_image + +name: real_pusht_pretrained_imagenet +_target_: diffusion_policy.workspace.train_diffusion_unet_image_workspace.TrainDiffusionUnetImageWorkspace + +task_name: ${task.name} +shape_meta: ${task.shape_meta} +exp_name: "default" + +horizon: 16 +n_obs_steps: 2 +n_action_steps: 8 +n_latency_steps: 0 +dataset_obs_steps: ${n_obs_steps} +past_action_visible: False +keypoint_visible_rate: 1.0 +obs_as_global_cond: True + +policy: + _target_: diffusion_policy.policy.diffusion_unet_image_policy.DiffusionUnetImagePolicy + + shape_meta: ${shape_meta} + + noise_scheduler: + _target_: diffusers.schedulers.scheduling_ddim.DDIMScheduler + num_train_timesteps: 100 + beta_start: 0.0001 + beta_end: 0.02 + # beta_schedule is important + # this is the best we found + beta_schedule: squaredcos_cap_v2 + clip_sample: True + set_alpha_to_one: True + steps_offset: 0 + prediction_type: epsilon # or sample + + obs_encoder: + _target_: diffusion_policy.model.vision.multi_image_obs_encoder.MultiImageObsEncoder + shape_meta: ${shape_meta} + rgb_model: + _target_: diffusion_policy.model.vision.model_getter.get_resnet + name: resnet18 + weights: IMAGENET1K_V1 # or r3m + # resize_shape: [224,224] + crop_shape: null + random_crop: False + use_group_norm: False + share_rgb_model: True + imagenet_norm: True + + horizon: ${horizon} + n_action_steps: ${eval:'${n_action_steps}+${n_latency_steps}'} + n_obs_steps: ${n_obs_steps} + num_inference_steps: 100 + obs_as_global_cond: ${obs_as_global_cond} + # crop_shape: null + diffusion_step_embed_dim: 128 + down_dims: [512, 1024, 2048] + kernel_size: 5 + n_groups: 8 + cond_predict_scale: True + + # scheduler.step params + # predict_epsilon: True + +ema: + _target_: diffusion_policy.model.diffusion.ema_model.EMAModel + update_after_step: 0 + inv_gamma: 1.0 + power: 0.75 + min_value: 0.0 + max_value: 0.9999 + +dataloader: + batch_size: 64 + num_workers: 8 + shuffle: True + pin_memory: True + persistent_workers: True + +val_dataloader: + batch_size: 64 + num_workers: 8 + shuffle: False + pin_memory: True + persistent_workers: True + +optimizer: + _target_: torch.optim.AdamW + lr: 1.0e-4 + betas: [0.95, 0.999] + eps: 1.0e-8 + weight_decay: 1.0e-6 + +training: + device: "cuda:0" + seed: 42 + debug: False + resume: True + # optimization + lr_scheduler: cosine + lr_warmup_steps: 100 + num_epochs: 600 + gradient_accumulate_every: 1 + # EMA destroys performance when used with BatchNorm + # replace BatchNorm with GroupNorm. + use_ema: True + freeze_encoder: True + # training loop control + # in epochs + rollout_every: 50 + checkpoint_every: 50 + val_every: 1 + sample_every: 5 + # steps per epoch + max_train_steps: null + max_val_steps: null + # misc + tqdm_interval_sec: 1.0 + +logging: + project: diffusion_policy_debug + resume: True + mode: online + name: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + tags: ["${name}", "${task_name}", "${exp_name}"] + id: null + group: null + +checkpoint: + topk: + monitor_key: train_loss + mode: min + k: 5 + format_str: 'epoch={epoch:04d}-train_loss={train_loss:.3f}.ckpt' + save_last_ckpt: True + save_last_snapshot: False + +multi_run: + run_dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + wandb_name_base: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + +hydra: + job: + override_dirname: ${name} + run: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + sweep: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + subdir: ${hydra.job.num} diff --git a/diffusion_policy/config/train_real_pusht_pretrained_r3m.yaml b/diffusion_policy/config/train_real_pusht_pretrained_r3m.yaml new file mode 100644 index 000000000..61b25a21f --- /dev/null +++ b/diffusion_policy/config/train_real_pusht_pretrained_r3m.yaml @@ -0,0 +1,152 @@ +defaults: + - _self_ + - task: real_pusht_image + +name: real_pusht_pretrained_r3m +_target_: diffusion_policy.workspace.train_diffusion_unet_image_workspace.TrainDiffusionUnetImageWorkspace + +task_name: ${task.name} +shape_meta: ${task.shape_meta} +exp_name: "default" + +horizon: 16 +n_obs_steps: 2 +n_action_steps: 8 +n_latency_steps: 0 +dataset_obs_steps: ${n_obs_steps} +past_action_visible: False +keypoint_visible_rate: 1.0 +obs_as_global_cond: True + +policy: + _target_: diffusion_policy.policy.diffusion_unet_image_policy.DiffusionUnetImagePolicy + + shape_meta: ${shape_meta} + + noise_scheduler: + _target_: diffusers.schedulers.scheduling_ddim.DDIMScheduler + num_train_timesteps: 100 + beta_start: 0.0001 + beta_end: 0.02 + # beta_schedule is important + # this is the best we found + beta_schedule: squaredcos_cap_v2 + clip_sample: True + set_alpha_to_one: True + steps_offset: 0 + prediction_type: epsilon # or sample + + obs_encoder: + _target_: diffusion_policy.model.vision.multi_image_obs_encoder.MultiImageObsEncoder + shape_meta: ${shape_meta} + rgb_model: + _target_: diffusion_policy.model.vision.model_getter.get_resnet + name: resnet18 + weights: r3m # or r3m + # resize_shape: [224,224] + crop_shape: null + random_crop: False + use_group_norm: False + share_rgb_model: True + imagenet_norm: True + + horizon: ${horizon} + n_action_steps: ${eval:'${n_action_steps}+${n_latency_steps}'} + n_obs_steps: ${n_obs_steps} + num_inference_steps: 100 + obs_as_global_cond: ${obs_as_global_cond} + # crop_shape: null + diffusion_step_embed_dim: 128 + down_dims: [512, 1024, 2048] + kernel_size: 5 + n_groups: 8 + cond_predict_scale: True + + # scheduler.step params + # predict_epsilon: True + +ema: + _target_: diffusion_policy.model.diffusion.ema_model.EMAModel + update_after_step: 0 + inv_gamma: 1.0 + power: 0.75 + min_value: 0.0 + max_value: 0.9999 + +dataloader: + batch_size: 64 + num_workers: 8 + shuffle: True + pin_memory: True + persistent_workers: True + +val_dataloader: + batch_size: 64 + num_workers: 8 + shuffle: False + pin_memory: True + persistent_workers: True + +optimizer: + _target_: torch.optim.AdamW + lr: 1.0e-4 + betas: [0.95, 0.999] + eps: 1.0e-8 + weight_decay: 1.0e-6 + +training: + device: "cuda:0" + seed: 42 + debug: False + resume: True + # optimization + lr_scheduler: cosine + lr_warmup_steps: 100 + num_epochs: 600 + gradient_accumulate_every: 1 + # EMA destroys performance when used with BatchNorm + # replace BatchNorm with GroupNorm. + use_ema: True + freeze_encoder: True + # training loop control + # in epochs + rollout_every: 50 + checkpoint_every: 50 + val_every: 1 + sample_every: 5 + # steps per epoch + max_train_steps: null + max_val_steps: null + # misc + tqdm_interval_sec: 1.0 + +logging: + project: diffusion_policy_debug + resume: True + mode: online + name: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + tags: ["${name}", "${task_name}", "${exp_name}"] + id: null + group: null + +checkpoint: + topk: + monitor_key: train_loss + mode: min + k: 5 + format_str: 'epoch={epoch:04d}-train_loss={train_loss:.3f}.ckpt' + save_last_ckpt: True + save_last_snapshot: False + +multi_run: + run_dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + wandb_name_base: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + +hydra: + job: + override_dirname: ${name} + run: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + sweep: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + subdir: ${hydra.job.num} diff --git a/diffusion_policy/config/train_robomimic.yaml b/diffusion_policy/config/train_robomimic.yaml new file mode 100644 index 000000000..4813bf16a --- /dev/null +++ b/diffusion_policy/config/train_robomimic.yaml @@ -0,0 +1,152 @@ +defaults: + - _self_ + - task: can_image_abs + +name: can_ph_end2end +_target_: diffusion_policy.workspace.train_diffusion_unet_image_workspace.TrainDiffusionUnetImageWorkspace + +task_name: ${task.name} +shape_meta: ${task.shape_meta} +exp_name: "default" + +horizon: 16 +n_obs_steps: 2 +n_action_steps: 8 +n_latency_steps: 0 +dataset_obs_steps: ${n_obs_steps} +past_action_visible: False +keypoint_visible_rate: 1.0 +obs_as_global_cond: True + +policy: + _target_: diffusion_policy.policy.diffusion_unet_image_policy.DiffusionUnetImagePolicy + + shape_meta: ${shape_meta} + + noise_scheduler: + _target_: diffusers.schedulers.scheduling_ddim.DDIMScheduler + num_train_timesteps: 100 + beta_start: 0.0001 + beta_end: 0.02 + # beta_schedule is important + # this is the best we found + beta_schedule: squaredcos_cap_v2 + clip_sample: True + set_alpha_to_one: True + steps_offset: 0 + prediction_type: epsilon # or sample + + obs_encoder: + _target_: diffusion_policy.model.vision.multi_image_obs_encoder.MultiImageObsEncoder + shape_meta: ${shape_meta} + rgb_model: + _target_: diffusion_policy.model.vision.model_getter.get_resnet + name: resnet18 + weights: null + # resize_shape: [240, 320] + crop_shape: [76, 76] # ch, cw 240x320 90% + random_crop: True + use_group_norm: True + share_rgb_model: False + imagenet_norm: True + + horizon: ${horizon} + n_action_steps: ${eval:'${n_action_steps}+${n_latency_steps}'} + n_obs_steps: ${n_obs_steps} + num_inference_steps: 100 + obs_as_global_cond: ${obs_as_global_cond} + # crop_shape: null + diffusion_step_embed_dim: 128 + down_dims: [512, 1024, 2048] + kernel_size: 5 + n_groups: 8 + cond_predict_scale: True + + # scheduler.step params + # predict_epsilon: True + +ema: + _target_: diffusion_policy.model.diffusion.ema_model.EMAModel + update_after_step: 0 + inv_gamma: 1.0 + power: 0.75 + min_value: 0.0 + max_value: 0.9999 + +dataloader: + batch_size: 64 + num_workers: 8 + shuffle: True + pin_memory: True + persistent_workers: True + +val_dataloader: + batch_size: 64 + num_workers: 8 + shuffle: False + pin_memory: True + persistent_workers: True + +optimizer: + _target_: torch.optim.AdamW + lr: 1.0e-4 + betas: [0.95, 0.999] + eps: 1.0e-8 + weight_decay: 1.0e-6 + +training: + device: "cuda:0" + seed: 42 + debug: False + resume: True + # optimization + lr_scheduler: cosine + lr_warmup_steps: 66 + num_epochs: 400 + gradient_accumulate_every: 1 + # EMA destroys performance when used with BatchNorm + # replace BatchNorm with GroupNorm. + use_ema: True + freeze_encoder: False + # training loop control + # in epochs + rollout_every: 20 + checkpoint_every: 20 + val_every: 1 + sample_every: 5 + # steps per epoch + max_train_steps: null + max_val_steps: null + # misc + tqdm_interval_sec: 1.0 + +logging: + project: diffusion_policy_debug + resume: True + mode: online + name: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + tags: ["${name}", "${task_name}", "${exp_name}"] + id: null + group: null + +checkpoint: + topk: + monitor_key: train_loss + mode: min + k: 5 + format_str: 'epoch={epoch:04d}-train_loss={train_loss:.3f}.ckpt' + save_last_ckpt: True + save_last_snapshot: False + +multi_run: + run_dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + wandb_name_base: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + +hydra: + job: + override_dirname: ${name} + run: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + sweep: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + subdir: ${hydra.job.num} diff --git a/diffusion_policy/config/train_robomimic_dinov2.yaml b/diffusion_policy/config/train_robomimic_dinov2.yaml new file mode 100644 index 000000000..e66efc80e --- /dev/null +++ b/diffusion_policy/config/train_robomimic_dinov2.yaml @@ -0,0 +1,151 @@ +defaults: + - _self_ + - task: can_image_abs + +name: can_ph_dino +_target_: diffusion_policy.workspace.train_diffusion_unet_image_workspace.TrainDiffusionUnetImageWorkspace + +task_name: ${task.name} +shape_meta: ${task.shape_meta} +exp_name: "default" + +horizon: 16 +n_obs_steps: 2 +n_action_steps: 8 +n_latency_steps: 0 +dataset_obs_steps: ${n_obs_steps} +past_action_visible: False +keypoint_visible_rate: 1.0 +obs_as_global_cond: True + +policy: + _target_: diffusion_policy.policy.diffusion_unet_image_policy.DiffusionUnetImagePolicy + + shape_meta: ${shape_meta} + + noise_scheduler: + _target_: diffusers.schedulers.scheduling_ddim.DDIMScheduler + num_train_timesteps: 100 + beta_start: 0.0001 + beta_end: 0.02 + # beta_schedule is important + # this is the best we found + beta_schedule: squaredcos_cap_v2 + clip_sample: True + set_alpha_to_one: True + steps_offset: 0 + prediction_type: epsilon # or sample + + obs_encoder: + _target_: diffusion_policy.model.vision.multi_image_obs_encoder.MultiImageObsEncoder + shape_meta: ${shape_meta} + rgb_model: + _target_: diffusion_policy.model.vision.model_getter.get_dinov2 + name: facebook/dinov2-base + crop_shape: null + random_crop: False + use_group_norm: False + share_rgb_model: True + imagenet_norm: False + rgb_model_name: facebook/dinov2-base + + horizon: ${horizon} + n_action_steps: ${eval:'${n_action_steps}+${n_latency_steps}'} + n_obs_steps: ${n_obs_steps} + num_inference_steps: 100 + obs_as_global_cond: ${obs_as_global_cond} + # crop_shape: null + diffusion_step_embed_dim: 128 + down_dims: [512, 1024, 2048] + kernel_size: 5 + n_groups: 8 + cond_predict_scale: True + + # scheduler.step params + # predict_epsilon: True + +ema: + _target_: diffusion_policy.model.diffusion.ema_model.EMAModel + update_after_step: 0 + inv_gamma: 1.0 + power: 0.75 + min_value: 0.0 + max_value: 0.9999 + +dataloader: + batch_size: 64 + num_workers: 8 + shuffle: True + pin_memory: True + persistent_workers: True + +val_dataloader: + batch_size: 64 + num_workers: 8 + shuffle: False + pin_memory: True + persistent_workers: True + +optimizer: + _target_: torch.optim.AdamW + lr: 1.0e-4 + betas: [0.95, 0.999] + eps: 1.0e-8 + weight_decay: 1.0e-6 + +training: + device: "cuda:0" + seed: 42 + debug: False + resume: True + # optimization + lr_scheduler: cosine + lr_warmup_steps: 66 + num_epochs: 400 + gradient_accumulate_every: 1 + # EMA destroys performance when used with BatchNorm + # replace BatchNorm with GroupNorm. + use_ema: True + freeze_encoder: True + # training loop control + # in epochs + rollout_every: 20 + checkpoint_every: 20 + val_every: 1 + sample_every: 5 + # steps per epoch + max_train_steps: null + max_val_steps: null + # misc + tqdm_interval_sec: 1.0 + +logging: + project: diffusion_policy_debug + resume: True + mode: online + name: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + tags: ["${name}", "${task_name}", "${exp_name}"] + id: null + group: null + +checkpoint: + topk: + monitor_key: train_loss + mode: min + k: 5 + format_str: 'epoch={epoch:04d}-train_loss={train_loss:.3f}.ckpt' + save_last_ckpt: True + save_last_snapshot: False + +multi_run: + run_dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + wandb_name_base: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + +hydra: + job: + override_dirname: ${name} + run: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + sweep: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + subdir: ${hydra.job.num} diff --git a/diffusion_policy/config/train_robomimic_r3m.yaml b/diffusion_policy/config/train_robomimic_r3m.yaml new file mode 100644 index 000000000..779154d32 --- /dev/null +++ b/diffusion_policy/config/train_robomimic_r3m.yaml @@ -0,0 +1,152 @@ +defaults: + - _self_ + - task: can_image_abs + +name: can_ph_r3m +_target_: diffusion_policy.workspace.train_diffusion_unet_image_workspace.TrainDiffusionUnetImageWorkspace + +task_name: ${task.name} +shape_meta: ${task.shape_meta} +exp_name: "default" + +horizon: 16 +n_obs_steps: 2 +n_action_steps: 8 +n_latency_steps: 0 +dataset_obs_steps: ${n_obs_steps} +past_action_visible: False +keypoint_visible_rate: 1.0 +obs_as_global_cond: True + +policy: + _target_: diffusion_policy.policy.diffusion_unet_image_policy.DiffusionUnetImagePolicy + + shape_meta: ${shape_meta} + + noise_scheduler: + _target_: diffusers.schedulers.scheduling_ddim.DDIMScheduler + num_train_timesteps: 100 + beta_start: 0.0001 + beta_end: 0.02 + # beta_schedule is important + # this is the best we found + beta_schedule: squaredcos_cap_v2 + clip_sample: True + set_alpha_to_one: True + steps_offset: 0 + prediction_type: epsilon # or sample + + obs_encoder: + _target_: diffusion_policy.model.vision.multi_image_obs_encoder.MultiImageObsEncoder + shape_meta: ${shape_meta} + rgb_model: + _target_: diffusion_policy.model.vision.model_getter.get_resnet + name: resnet18 + weights: r3m # or r3m + # resize_shape: [224,224] + crop_shape: null + random_crop: False + use_group_norm: False + share_rgb_model: True + imagenet_norm: True + + horizon: ${horizon} + n_action_steps: ${eval:'${n_action_steps}+${n_latency_steps}'} + n_obs_steps: ${n_obs_steps} + num_inference_steps: 100 + obs_as_global_cond: ${obs_as_global_cond} + # crop_shape: null + diffusion_step_embed_dim: 128 + down_dims: [512, 1024, 2048] + kernel_size: 5 + n_groups: 8 + cond_predict_scale: True + + # scheduler.step params + # predict_epsilon: True + +ema: + _target_: diffusion_policy.model.diffusion.ema_model.EMAModel + update_after_step: 0 + inv_gamma: 1.0 + power: 0.75 + min_value: 0.0 + max_value: 0.9999 + +dataloader: + batch_size: 64 + num_workers: 8 + shuffle: True + pin_memory: True + persistent_workers: True + +val_dataloader: + batch_size: 64 + num_workers: 8 + shuffle: False + pin_memory: True + persistent_workers: True + +optimizer: + _target_: torch.optim.AdamW + lr: 1.0e-4 + betas: [0.95, 0.999] + eps: 1.0e-8 + weight_decay: 1.0e-6 + +training: + device: "cuda:0" + seed: 42 + debug: False + resume: True + # optimization + lr_scheduler: cosine + lr_warmup_steps: 66 + num_epochs: 400 + gradient_accumulate_every: 1 + # EMA destroys performance when used with BatchNorm + # replace BatchNorm with GroupNorm. + use_ema: True + freeze_encoder: True + # training loop control + # in epochs + rollout_every: 20 + checkpoint_every: 20 + val_every: 1 + sample_every: 5 + # steps per epoch + max_train_steps: null + max_val_steps: null + # misc + tqdm_interval_sec: 1.0 + +logging: + project: diffusion_policy_debug + resume: True + mode: online + name: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + tags: ["${name}", "${task_name}", "${exp_name}"] + id: null + group: null + +checkpoint: + topk: + monitor_key: train_loss + mode: min + k: 5 + format_str: 'epoch={epoch:04d}-train_loss={train_loss:.3f}.ckpt' + save_last_ckpt: True + save_last_snapshot: False + +multi_run: + run_dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + wandb_name_base: ${now:%Y.%m.%d-%H.%M.%S}_${name}_${task_name} + +hydra: + job: + override_dirname: ${name} + run: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + sweep: + dir: data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name} + subdir: ${hydra.job.num} diff --git a/diffusion_policy/model/vision/multi_image_obs_encoder.py b/diffusion_policy/model/vision/multi_image_obs_encoder.py index ccd76b07d..fc9fda5e2 100644 --- a/diffusion_policy/model/vision/multi_image_obs_encoder.py +++ b/diffusion_policy/model/vision/multi_image_obs_encoder.py @@ -5,6 +5,7 @@ import torch.nn as nn import torchvision import transformers +from transformers import AutoImageProcessor from diffusion_policy.common.pytorch_util import dict_apply, replace_submodules from diffusion_policy.model.common.module_attr_mixin import ModuleAttrMixin @@ -24,7 +25,8 @@ def __init__(self, share_rgb_model: bool=False, # renormalize rgb input with imagenet normalization # assuming input in [0,1] - imagenet_norm: bool=False + imagenet_norm: bool=False, + rgb_model_name: str=None, ): """ Assumes rgb input: B,C,H,W @@ -126,6 +128,13 @@ def __init__(self, self.rgb_keys = rgb_keys self.low_dim_keys = low_dim_keys self.key_shape_map = key_shape_map + self.rgb_model_name = rgb_model_name + self.predefined_image_processor = None + if ( + self.rgb_model_name == "facebook/dinov2-base" + or self.rgb_model_name == "facebook/dinov2-large" + ): + self.predefined_image_processor = AutoImageProcessor.from_pretrained(self.rgb_model_name) def forward(self, obs_dict): batch_size = None @@ -146,8 +155,18 @@ def forward(self, obs_dict): # (N*B,C,H,W) imgs = torch.cat(imgs, dim=0) # (N*B,D) - if isinstance(self.key_model_map['rgb'], transformers.models.dinov2.modeling_dinov2.Dinov2Model): - feature = self.key_model_map["rgb"](imgs)[0].mean(dim=1) + if ( + self.rgb_model_name == "facebook/dinov2-base" + or self.rgb_model_name == "facebook/dinov2-large" + ): + imgs = (imgs * 255).type(torch.uint8) + inputs = self.predefined_image_processor( + images=imgs, + return_tensors="pt", + ) + inputs['pixel_values'] = inputs['pixel_values'].to(self.device) + outputs = self.key_model_map["rgb"](**inputs) + feature = outputs[0].mean(dim=1) else: feature = self.key_model_map["rgb"](imgs) # (N,B,D) diff --git a/scripts/fix_mujoco.sh b/scripts/fix_mujoco.sh new file mode 100755 index 000000000..d4b0c89ad --- /dev/null +++ b/scripts/fix_mujoco.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -e + +echo "Activating environment..." +eval "$(conda shell.bash hook)" + +mamba activate robodiff +mamba install -c conda-forge glew +mamba install -c conda-forge mesalib +mamba install -c anaconda mesa-libgl-cos6-x86_64 +mamba install -c menpo glfw3 + +conda env config vars set MUJOCO_GL=egl PYOPENGL_PLATFORM=egl +conda deactivate && conda activate robodiff + +pip install patchelf + +echo "Adding environment variable to bashrc" +#!/usr/bin/env bash + +# Lines to add +LINES=( +'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/portegak/.mujoco/mujoco210/bin' +'#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia' +'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/miniforge3/envs/robodiff/include' +) + +BASHRC="$HOME/.bashrc" + +# Check if each line already exists in .bashrc, if not, append it +for LINE in "${LINES[@]}"; do + # Escape special characters for grep + ESCAPED_LINE=$(printf '%s\n' "$LINE" | sed 's/[][\.*^$(){}?+|]/\\&/g') + + if ! grep -qxF "$LINE" "$BASHRC" 2>/dev/null; then + echo "$LINE" >> "$BASHRC" + echo "Added: $LINE" + else + echo "Already present: $LINE" + fi +done + +echo "Done. To apply changes, run: source $BASHRC" diff --git a/scripts/run_eval.sh b/scripts/run_eval.sh new file mode 100755 index 000000000..7cd23c63b --- /dev/null +++ b/scripts/run_eval.sh @@ -0,0 +1,3 @@ + +CUDA_VISIBLE_DEVICES=1 +python eval.py --checkpoint data/outputs/2024.12.10/14.11.59_real_pusht_end2end_real_image/checkpoints/latest.ckpt -o data/pusht_real_eval_output diff --git a/scripts/train_dino.sh b/scripts/train_dino.sh new file mode 100755 index 000000000..763f168ce --- /dev/null +++ b/scripts/train_dino.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +CONFIG_FOLDER="diffusion_policy/config" + +echo "Running PushT with DinoBase" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_pusht_pretrained_dinov2_base.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + +echo "Running PushT with DinoLarge" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_pusht_pretrained_dinov2_large.yaml training.seed=42 training.device=cuda:1 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' \ No newline at end of file diff --git a/scripts/train_real_pusht _gpu1.sh b/scripts/train_real_pusht _gpu1.sh new file mode 100755 index 000000000..4ca03078d --- /dev/null +++ b/scripts/train_real_pusht _gpu1.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e +CONFIG_FOLDER="diffusion_policy/config" + +echo "Running RealPushT with End2End" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_real_pusht.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + +echo "Running RealPushT with DinoV2" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_real_pusht_pretrained_dinov2_base.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + +echo "Running RealPushT with R3M" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_real_pusht_pretrained_r3m.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + +echo "Running RealPushT with ImageNet" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_real_pusht_pretrained_imagenet.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + diff --git a/scripts/train_real_pusht.sh b/scripts/train_real_pusht.sh new file mode 100755 index 000000000..4ca03078d --- /dev/null +++ b/scripts/train_real_pusht.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e +CONFIG_FOLDER="diffusion_policy/config" + +echo "Running RealPushT with End2End" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_real_pusht.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + +echo "Running RealPushT with DinoV2" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_real_pusht_pretrained_dinov2_base.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + +echo "Running RealPushT with R3M" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_real_pusht_pretrained_r3m.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + +echo "Running RealPushT with ImageNet" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_real_pusht_pretrained_imagenet.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + diff --git a/scripts/train_robomimic.sh b/scripts/train_robomimic.sh new file mode 100755 index 000000000..b33fdd5a2 --- /dev/null +++ b/scripts/train_robomimic.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e +CONFIG_FOLDER="diffusion_policy/config" + +echo "Running Can lift with DinoBase" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_robomimic_dinov2.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + +echo "Running Can lift with End2End" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_robomimic.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' + +echo "Running Can lift with R3M" +python train.py --config-dir=$CONFIG_FOLDER --config-name=train_robomimic_r3m.yaml training.seed=42 training.device=cuda:0 hydra.run.dir='data/outputs/${now:%Y.%m.%d}/${now:%H.%M.%S}_${name}_${task_name}' +