forked from openvla/openvla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vla.py
235 lines (168 loc) · 8.87 KB
/
vla.py
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
"""
vla.py
Draccus Dataclass Definition for a VLAConfig object, with various registered subclasses for each VLA experiment and
model configuration thereof. A given VLA model (`policy`) configures the following attributes:
- Data Mixture (e.g., Bridge, OXE_MAGIC_SOUP, etc.)
- Base VLM from Prismatic Registry (e.g., `prism-dinosiglip+7b`)
- VLA Model Architecture / Parameters (e.g., freeze vision encoder, last layer finetuning)
- Training / Optimization Hyperparameters
"""
from dataclasses import dataclass
from enum import Enum, unique
from pathlib import Path
from typing import Optional, Union
from draccus import ChoiceRegistry
@dataclass
class VLAConfig(ChoiceRegistry):
# fmt: off
vla_id: str # Unique VLA Policy ID that fully specifies a configuration variant
base_vlm: Union[str, Path] # Base VLM as ID/Path to Run Directory (e.g., `prism-dinosiglip+7b`)
freeze_vision_backbone: bool # Freeze Vision Backbone Parameters (akin to pretraining)
freeze_llm_backbone: bool # Freeze LLM Backbone parameters
unfreeze_last_llm_layer: bool # Unfreeze final layer of LLM (only takes effect if LLM is frozen)
# Data Mixture Parameters
data_mix: str # Open-X Embodiment Dataset =>> Unique Mixture ID (e.g., `bridge`)
shuffle_buffer_size: int # Size of Shuffle Buffer (100K for Bridge, 1M for OXE)
# Optimization Parameters
epochs: int # Epochs to Run (in case `max_steps` is not specified)
max_steps: Optional[int] # [Optional] Max Gradient Steps to Run (overrides `epochs`)
expected_world_size: int # Expected # of GPUs =>> allows us to gate training on hardware
global_batch_size: int # Global Batch Size (divided across processes / world size)
per_device_batch_size: int # Per-Device Batch Size (per-process / individual GPU)
# =>> # of accumulation steps is auto-computed
learning_rate: float # Peak Learning Rate (`lr_scheduler_type` sets warmup/decay)
weight_decay: float # Weight Decay for AdamW Optimizer
max_grad_norm: float # Max Grad Norm (for global gradient clipping)
lr_scheduler_type: str # LR Scheduler (usually: "constant" | "linear-warmup+cosine-decay")
warmup_ratio: float # Fraction of Steps to Warmup (for warmup LR schedulers)
train_strategy: str # Train Strategy (default "fsdp-full-shard")
# Enable Gradient/Activation Checkpointing (for the LLM Backbone)
enable_gradient_checkpointing: bool = True # Enable Gradient/Activation Checkpointing during Training
# Mixed Precision Training via Torch Native AMP (`autocast`)
enable_mixed_precision_training: bool = True # Enable Traditional BF16 Mixed Precision
reduce_in_full_precision: bool = True # Accumulate/Reduce All-Gather Gradients in FP32 Full Precision
# fmt: on
# === OpenVLA Training Configurations ===
# = [8 GPU] Fast Iteration =>> SigLIP 224px + Bridge =
@dataclass
class Exp_SigLIP_224px_Bridge(VLAConfig):
vla_id: str = "siglip-224px+mx-bridge"
base_vlm: Union[str, Path] = "siglip-224px+7b"
freeze_vision_backbone: bool = False
freeze_llm_backbone: bool = False
unfreeze_last_llm_layer: bool = False
# Data Mixture Parameters
data_mix: str = "bridge"
shuffle_buffer_size: int = 256_000
# Optimization Parameters
epochs: int = 1000
max_steps: Optional[int] = None
expected_world_size: int = 8
global_batch_size: int = 256
per_device_batch_size: int = 32
learning_rate: float = 2e-5
weight_decay: float = 0.0
max_grad_norm: float = 1.0
lr_scheduler_type: str = "constant"
warmup_ratio: float = 0.0
train_strategy: str = "fsdp-full-shard"
# = [8 GPU] SigLIP 224px Frozen Vision Backbone + Bridge =
@dataclass
class Exp_FreezeVIT_SigLIP_224px_Bridge(Exp_SigLIP_224px_Bridge):
vla_id: str = "siglip-224px-icy+mx-bridge"
base_vlm: Union[str, Path] = "siglip-224px+7b"
freeze_vision_backbone: bool = True
# = [8 GPU] Fast Iteration =>> DINO-SigLIP 224px + Bridge =
@dataclass
class Exp_DinoSigLIP_224px_Bridge(Exp_SigLIP_224px_Bridge):
vla_id: str = "prism-dinosiglip-224px+mx-bridge"
base_vlm: Union[str, Path] = "prism-dinosiglip-224px+7b"
data_mix: str = "bridge"
# = [64 GPU] SigLIP 224px + OXE Magic Soup =
@dataclass
class Exp_SigLIP_224px_OXE_Magic_Soup(Exp_SigLIP_224px_Bridge):
vla_id: str = "siglip-224px+mx-oxe-magic-soup"
base_vlm: Union[str, Path] = "siglip-224px+7b"
data_mix: str = "oxe_magic_soup"
expected_world_size: int = 64
global_batch_size: int = 2048
per_device_batch_size: int = 32
# = [64 GPU] DINO-SigLIP 224px + OXE Magic Soup++ =
@dataclass
class Exp_DinoSigLIP_224px_OXE_Magic_Soup_Plus(Exp_SigLIP_224px_Bridge):
vla_id: str = "prism-dinosiglip-224px+mx-oxe-magic-soup-plus"
base_vlm: Union[str, Path] = "prism-dinosiglip-224px+7b"
# Note =>> We adopt two stages, training on a mixture including DROID for 70% of training, before resampling!
# data_mix: str = "oxe_magic_soup_plus"
data_mix: str = "oxe_magic_soup_plus_minus"
expected_world_size: int = 64
global_batch_size: int = 2048
per_device_batch_size: int = 32
# === OpenVLA Fine-tuning Configurations ===
# = [8 GPU] SigLIP 224px + T-DROID =
@dataclass
class Exp_SigLIP_224px_TDROID_CarrotInBowl(Exp_SigLIP_224px_Bridge):
vla_id: str = "siglip-224px+mx-tdroid_carrot_in_bowl"
base_vlm: Union[str, Path] = "siglip-224px+7b"
data_mix: str = "tdroid_carrot_in_bowl"
@dataclass
class Exp_SigLIP_224px_TDROID_PourCornInPot(Exp_SigLIP_224px_Bridge):
vla_id: str = "siglip-224px+mx-tdroid_pour_corn_in_pot"
base_vlm: Union[str, Path] = "siglip-224px+7b"
data_mix: str = "tdroid_pour_corn_in_pot"
# = [8 GPU] SigLIP 224px + T-DROID -- Partial Finetuning =
@dataclass
class Exp_SigLIP_224px_Icy_TDROID_CarrotInBowl(Exp_SigLIP_224px_Bridge):
vla_id: str = "siglip-224px-icy+mx-tdroid_carrot_in_bowl"
base_vlm: Union[str, Path] = "siglip-224px+7b"
freeze_vision_backbone: bool = True
freeze_llm_backbone: bool = False
data_mix: str = "tdroid_carrot_in_bowl"
@dataclass
class Exp_SigLIP_224px_LastLayer_TDROID_CarrotInBowl(Exp_SigLIP_224px_Bridge):
vla_id: str = "siglip-224px-last_layer+mx-tdroid_carrot_in_bowl"
base_vlm: Union[str, Path] = "siglip-224px+7b"
freeze_vision_backbone: bool = True
freeze_llm_backbone: bool = True
unfreeze_last_llm_layer: bool = True
data_mix: str = "tdroid_carrot_in_bowl"
@dataclass
class Exp_SigLIP_224px_Sandwich_TDROID_CarrotInBowl(Exp_SigLIP_224px_Bridge):
vla_id: str = "siglip-224px-sandwich+mx-tdroid_carrot_in_bowl"
base_vlm: Union[str, Path] = "siglip-224px+7b"
freeze_vision_backbone: bool = False
freeze_llm_backbone: bool = True
unfreeze_last_llm_layer: bool = True
data_mix: str = "tdroid_carrot_in_bowl"
# === [8 GPU] SigLIP 224px + FrankaWipe ===
@dataclass
class Exp_SigLIP_224px_Droid_Wipe(Exp_SigLIP_224px_Bridge):
vla_id: str = "siglip-224px+mx-droid_wipe"
base_vlm: Union[str, Path] = "siglip-224px+7b"
data_mix: str = "droid_wipe"
# === Define a VLA Registry Enum for Reference & Validation ===
@unique
class VLARegistry(Enum):
# Sanity Check Configurations =>> BridgeV2
SIGLIP_224PX_MX_BRIDGE = Exp_SigLIP_224px_Bridge
DINOSIGLIP_224PX_MX_BRIDGE = Exp_DinoSigLIP_224px_Bridge
# SigLIP Frozen Backbone Experiment
FREEZE_SIGLIP_224PX_MX_BRIDGE = Exp_FreezeVIT_SigLIP_224px_Bridge
# [OpenVLA v0.1 7B] SigLIP 224px + OXE Magic Soup
SIGLIP_224PX_MX_OXE_MAGIC_SOUP = Exp_SigLIP_224px_OXE_Magic_Soup
# [OpenVLA 7B] DINO + SigLIP 224px + OXE Magic Soup++
DINOSIGLIP_224PX_MX_OXE_MAGIC_SOUP_PLUS = Exp_DinoSigLIP_224px_OXE_Magic_Soup_Plus
# === TDROID Fine-tuning Configs ===
SIGLIP_224PX_MX_TDROID_CARROT_IN_BOWL = Exp_SigLIP_224px_TDROID_CarrotInBowl
SIGLIP_224PX_MX_TDROID_POUR_CORN_IN_POT = Exp_SigLIP_224px_TDROID_PourCornInPot
SIGLIP_224PX_ICY_MX_TDROID_CARROT_IN_BOWL = Exp_SigLIP_224px_Icy_TDROID_CarrotInBowl
SIGLIP_224PX_LASTLAYER_MX_TDROID_CARROT_IN_BOWL = Exp_SigLIP_224px_LastLayer_TDROID_CarrotInBowl
SIGLIP_224PX_SANDWICH_MX_TDROID_CARROT_IN_BOWL = Exp_SigLIP_224px_Sandwich_TDROID_CarrotInBowl
# === DROID Fine-tuning Configs ===
SIGLIP_224PX_MX_DROID_WIPE = Exp_SigLIP_224px_Droid_Wipe
@property
def vla_id(self) -> str:
return self.value.vla_id
# Register VLAs in Choice Registry
for vla_variant in VLARegistry:
VLAConfig.register_subclass(vla_variant.vla_id, vla_variant.value)