forked from baidu-baige/LoongForge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraining_args.py
More file actions
1319 lines (1235 loc) · 44.1 KB
/
Copy pathtraining_args.py
File metadata and controls
1319 lines (1235 loc) · 44.1 KB
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2026 The LoongForge Authors.
# SPDX-License-Identifier: Apache-2.0
"""Generic training args + CLI front-end (single module).
This module is the single source of truth for the generic, model-independent
training parameters (``TrainingArgs``, a frozen dataclass instantiated from the
CLI) plus the tooling that turns that dataclass into an argparse CLI.
Usage rules (must follow)
-------------------------
1. Always read fields via direct attribute access: ``training_args.lr_base``.
2. Never use ``getattr(training_args, "x", default)`` or ``cfg.get("x", default)``:
- a default supplied there creates a second source of truth and hides the real one;
- a misspelled field should raise ``AttributeError`` immediately, not silently return
a fallback.
3. To add or change a generic parameter, edit only the matching concern-scoped
``_XxxArgs`` mixin dataclass (still one authoritative definition per field);
``TrainingArgs`` aggregates the mixins via multiple inheritance and stays a
single flat frozen dataclass, so the CLI flags, ``--help``, and the parameter
summary are all generated from it by reflection and attribute access stays
flat (``training_args.lr_base``).
Boundary: model-structure switches (freeze_vision_encoder, train_expert_only,
compile_model, ...) live in the per-model ModelConfig (YAML model:). Generic
runtime behavior, including framework-managed activation checkpoint selection,
lives here. Data-processing params (image_size, normalization_mode, ...) live in
the per-model DataConfig (YAML data:).
"""
import argparse
import dataclasses
from dataclasses import dataclass, field
from typing import Any, List, Optional, get_args, get_origin, Union
import torch
_FSDP_CONCRETE_DTYPE_CHOICES = ("fp32", "bf16", "fp16")
_FSDP_DTYPE_BY_NAME = {
"fp32": torch.float32,
"bf16": torch.bfloat16,
"fp16": torch.float16,
}
# ---------------------------------------------------------------------------
# Custom CLI value parsers (referenced by field metadata below)
# ---------------------------------------------------------------------------
def parse_reshard_after_forward(value: str):
"""Parse FSDP2 reshard_after_forward from CLI text: true|false|none|int>1."""
normalized = value.strip().lower()
if normalized in {"true", "t"}:
return True
if normalized in {"false", "f"}:
return False
if normalized in {"none", "null"}:
return None
try:
int_value = int(value)
except ValueError as exc:
raise argparse.ArgumentTypeError(
"expected one of: true, false, none, or an integer greater than 1"
) from exc
if int_value <= 1:
raise argparse.ArgumentTypeError(
"integer reshard_after_forward must be greater than 1"
)
return int_value
def parse_reshard_after_forward_map(value: str):
"""Parse comma-separated ClassName=value pairs for per-module FSDP reshard."""
result = {}
for item in value.split(","):
item = item.strip()
if not item:
continue
if "=" not in item:
raise argparse.ArgumentTypeError(
"expected comma-separated ClassName=value pairs"
)
class_name, raw_value = item.split("=", 1)
class_name = class_name.strip()
if not class_name:
raise argparse.ArgumentTypeError("empty class name in reshard map")
result[class_name] = parse_reshard_after_forward(raw_value)
return result
def parse_positive_int(value: str) -> int:
"""Parse a positive integer CLI value."""
try:
int_value = int(value)
except ValueError as exc:
raise argparse.ArgumentTypeError("expected a positive integer") from exc
if int_value <= 0:
raise argparse.ArgumentTypeError("expected a positive integer")
return int_value
def parse_module_key_patterns(
value: str | None,
*,
option_name: str,
) -> list[str]:
"""Parse comma-separated qualified module-key patterns."""
normalized_patterns = (value or "").strip()
if not normalized_patterns:
return []
patterns = [
pattern.strip()
for pattern in normalized_patterns.split(",")
if pattern.strip()
]
if any(
any(not segment for segment in pattern.split("."))
for pattern in patterns
):
raise ValueError(f"{option_name} cannot contain empty segments")
return patterns
# ---------------------------------------------------------------------------
# TrainingArgs - single source of truth for generic training params
#
# The parameters are split into concern-scoped mixin dataclasses (_XxxArgs)
# below; ``TrainingArgs`` aggregates them via multiple inheritance and remains a
# single flat frozen dataclass. Attribute access stays flat
# (``training_args.lr_base``) and the CLI/serialization behavior is unchanged.
# To add or change a generic parameter, edit the matching _XxxArgs mixin.
# ---------------------------------------------------------------------------
@dataclass(frozen=True)
class _ModelRoutingArgs:
"""Model routing: which YAML / trainer / tokenizer to select."""
# ── Model routing (which YAML / trainer / tokenizer) ──
model_name: Optional[str] = field(
default=None,
metadata={
"help": "Model identifier (e.g. 'pi05', 'groot_n1_6'). Selects the "
"ModelConfig/DataConfig classes and default YAML via "
"MODEL_SCHEMA. Required."
},
)
config_file: Optional[str] = field(
default=None,
metadata={
"help": "Explicit path to a model YAML config. Overrides the default "
"YAML resolved from --model-name; --model-name is still "
"required to pick the config classes."
},
)
tokenizer_path: Optional[str] = field(
default=None,
metadata={
"help": "Directory or HF repo id of the tokenizer. Exported to the "
"TOKENIZER_PATH env var so the model/data tokenizer loaders "
"can pick it up."
},
)
trainer_type: str = field(
default="FinetuneTrainer",
metadata={
"help": "Trainer class to instantiate (e.g. FinetuneTrainer, "
"GrootN1d6Trainer); resolved by the trainer builder registry."
},
)
@dataclass(frozen=True)
class _BasicTrainingArgs:
"""Basic training loop control, seeding, and output directory."""
train_iters: int = field(
default=150000,
metadata={
"help": "Total number of optimizer update steps to run before stopping."
},
)
save_interval: int = field(
default=10000,
metadata={"help": "Write a checkpoint every N iterations; 0 disables saving."},
)
seed: int = field(
default=3047,
metadata={
"help": "Global RNG seed for Python/NumPy/PyTorch and data shuffling "
"(reproducibility)."
},
)
deterministic_mode: bool = field(
default=False,
metadata={
"help": "Force cuDNN deterministic algorithms. Improves "
"reproducibility at some throughput cost; requires "
"CUBLAS_WORKSPACE_CONFIG to be set."
},
)
disable_tf32: bool = field(
default=False,
metadata={
"help": "disable"
"torch.backends.cudnn.allow_tf32"
"torch.backends.cuda.matmul.allow_tf32"
},
)
output_dir: str = field(
default="outputs/default",
metadata={
"help": "Root directory for checkpoints, logs, and other run artifacts."
},
)
gradient_accumulation_steps: int = field(
default=1,
metadata={
"help": "Number of micro-batches accumulated before each optimizer "
"step; effective batch = per_device_batch_size * world_size "
"* this value."
},
)
loss_spike_threshold: float = field(
default=100.0,
metadata={
"help": "Loss spike guard threshold. The scaled backward loss "
"(loss / gradient_accumulation_steps) is checked each "
"micro-batch; if it is NaN/Inf or greater than this value, "
"that loss contribution is zeroed before backward and the "
"optimizer iteration is counted as spiked/skipped."
},
)
manual_gc: bool = field(
default=False,
metadata={
"help": "Disable automatic Python GC and collect explicitly after optimizer steps."
},
)
manual_gc_interval: int = field(
default=0,
metadata={
"help": "Manual GC cadence in steps when --manual-gc is enabled; "
"0 disables periodic collection."
},
)
check_for_nan_in_loss_and_grad: bool = field(
default=True,
metadata={
"help": "Run host-side NaN/Inf checks on loss and gradients each step."
},
)
@dataclass(frozen=True)
class _LearningRateArgs:
"""Learning rate, LR groups, and LR schedules (see diagrams below)."""
lr_base: float = field(
default=2.5e-5,
metadata={
"help": "Base learning rate applied to all parameters not matched by "
"--lr-group."
},
)
lr_group: Optional[str] = field(
default=None,
metadata={
"help": "Per-module LR overrides in 'module.path=lr' format, "
"comma-separated. Order matters: parameters are assigned to "
"the first matching entry and excluded from all later entries. "
"Child module paths must appear before their parent paths, "
"otherwise the child rule is silently ignored because its "
"parameters have already been consumed by the parent. "
"Example: 'model.paligemma_with_expert.gemma_expert=1e-4,"
"model.paligemma_with_expert=1e-5'. The final catch-all "
"group uses --lr-base."
},
)
# ============================================================
# Learning Rate Schedules (relative LR vs optimizer step)
#
# Notation:
# W : warmup steps
# T : total training steps
# C : cycle length (per-cycle span)
# peak: maximum LR (after warmup)
# min : minimum LR
# lr_end: final LR for polynomial decay
#
# Axes:
# y-axis: lr (relative scale)
# x-axis: step →
#
# ------------------------------------------------------------
# linear (warmup + linear decay to 0):
#
# lr ^
# | /\
# | / \
# | / \
# |______________/ \____________ 0
# +---------------W------T-----------> step
#
# warmup: 0 → peak (linear)
# decay : peak → 0 (linear)
#
# ------------------------------------------------------------
# cosine (warmup + cosine decay to 0):
#
# lr ^
# | /\
# | / `-.
# | / `-.
# |______________/ `______ 0
# +---------------W-----------T----> step
#
# decay follows: 0.5 * (1 + cos(pi * t))
#
# ------------------------------------------------------------
# cosine_with_restarts (periodic cosine decay):
#
# lr ^
# | /\ /\ /\
# | / \ / \ / \
# | / \ / \ / \
# |_________/ \/ \/ \___ 0
# +-----------W-----------------------> step
#
# each cycle: cosine decay from peak → 0
# cycles repeat with period C
#
# ------------------------------------------------------------
# polynomial (warmup + polynomial decay):
#
# lr ^
# | /\
# | / `.
# | / `.
# |______________/ `_______ lr_end
# +---------------W--------T------> step
#
# decay: (1 - t/T)^p
#
# ------------------------------------------------------------
# constant:
#
# lr ^
# | ============================== peak
# |
# +------------------------------------> step
#
# ------------------------------------------------------------
# constant_with_warmup:
#
# lr ^
# | /=================== peak
# | /
# |______________/
# +---------------W--------------------> step
#
# ------------------------------------------------------------
# inverse_sqrt (Transformer-style):
#
# lr ^
# | /\
# | / `--.
# | / `--.
# |_____________/ `--... ~1/sqrt(step)
# +---------------W------------------> step
#
# warmup: linear
# decay : ∝ step^(-0.5)
#
# ------------------------------------------------------------
# cosine_with_min_lr:
#
# lr ^
# | /\
# | / `-.
# | / `-.
# min|______________/ `------ min
# +---------------W-----------T----> step
#
# ------------------------------------------------------------
# cosine_warmup_with_min_lr:
#
# lr ^
# | ./\
# | / `-.
# | / `-.
# min|__________/ `------ min
# +---------------W-----------T--> step
#
# warmup start ≈ peak / W (if not explicitly set)
#
# ------------------------------------------------------------
# lambda_linear (multi-cycle linear warmup + linear decay):
#
# lr ^
# | /\ /\ /\
# | / \ / \ / \
# | / \ / \ / \
# min|_________/ \______/ \______/ \______
# | W C W C W C
# +--------------------------------------------------> step
#
# Per cycle:
# warmup: f_start → f_max (linear, over W)
# decay : f_max → f_min (linear, over C - W)
#
# Global step is partitioned into consecutive cycles of length C
#
# ============================================================
lr_decay_style: str = field(
default="cosine_with_min_lr",
metadata={
"choices": [
"linear",
"cosine",
"cosine_with_restarts",
"polynomial",
"constant",
"constant_with_warmup",
"inverse_sqrt",
"cosine_with_min_lr",
"cosine_warmup_with_min_lr",
"lambda_linear",
],
"help": "Learning-rate scheduler name. Most values are passed to "
"transformers.get_scheduler; lambda_linear uses the custom "
"LambdaLinearScheduler."
},
)
lr_warmup_iters: int = field(
default=2000,
metadata={
"help": "Number of iterations to linearly warm up the LR from 0 to "
"its peak."
},
)
lr_decay_iters: Optional[int] = field(
default=None,
metadata={
"help": "Number of scheduler decay steps. Defaults to --train-iters when unset."
},
)
min_lr: float = field(
default=1e-6,
metadata={"help": "Lower bound the LR schedule decays to (floor)."},
)
# ── lambda_linear scheduler params ──
lambda_f_max: float = field(
default=0.4,
metadata={
"help": "lambda_linear: peak LR multiplier (applied after warmup). "
"Only used when --lr-decay-style=lambda_linear."
},
)
lambda_f_min: float = field(
default=0.0,
metadata={
"help": "lambda_linear: minimum LR multiplier (floor of each cycle). "
"Only used when --lr-decay-style=lambda_linear."
},
)
lambda_f_start: float = field(
default=0.0,
metadata={
"help": "lambda_linear: LR multiplier at the start of warmup. "
"Only used when --lr-decay-style=lambda_linear."
},
)
lambda_cycle_length: Optional[int] = field(
default=None,
metadata={
"help": "lambda_linear: number of steps per cycle. Defaults to "
"--train-iters when unset. "
"Only used when --lr-decay-style=lambda_linear."
},
)
# ── polynomial scheduler params ──
lr_end: float = field(
default=1e-7,
metadata={
"help": "polynomial: final LR value at the end of decay. "
"Only used when --lr-decay-style=polynomial."
},
)
polynomial_power: float = field(
default=1.0,
metadata={
"help": "polynomial: power factor of the decay curve. "
"Only used when --lr-decay-style=polynomial."
},
)
# ── cosine_with_restarts scheduler params ──
num_cycles: float = field(
default=1.0,
metadata={
"help": "cosine_with_restarts: number of hard restart cycles. "
"Only used when --lr-decay-style=cosine_with_restarts."
},
)
@dataclass(frozen=True)
class _OptimizerArgs:
"""Optimizer selection, gradient clipping, and weight decay."""
optimizer: str = field(
default="AdamW",
metadata={
"help": "Optimizer name. Supported: AdamW, TorchFusedAdamW, "
"TEFusedAdamW, ApexFusedAdamW, Adam, SGD. TEFusedAdamW "
"requires TransformerEngine; ApexFusedAdamW requires Apex."
},
)
clip_grad: float = field(
default=1.0,
metadata={
"help": "Max global gradient norm for clipping; <=0 disables clipping."
},
)
weight_decay: float = field(
default=0.01,
metadata={"help": "Decoupled weight decay coefficient (AdamW)."},
)
weight_decay_grouping: str = field(
default="all",
metadata={
"choices": ["all", "bias_norm"],
"help": "How weight decay is applied: 'all' applies --weight-decay to every "
"trainable parameter; 'bias_norm' excludes bias and norm parameters.",
},
)
adam_beta1: float = field(
default=0.9,
metadata={
"help": "Adam beta1 — exponential decay rate for the first moment "
"(mean)."
},
)
adam_beta2: float = field(
default=0.95,
metadata={
"help": "Adam beta2 — exponential decay rate for the second moment "
"(variance)."
},
)
adam_eps: float = field(
default=1e-8,
metadata={
"help": "Adam epsilon added to the denominator for numerical stability."
},
)
@dataclass(frozen=True)
class _DataArgs:
"""Data loading control (cross-model; per-model processing lives in DataConfig)."""
dataset_format: str = field(
default="lerobot_datasets",
metadata={
"help": "Dataset backend to use "
"(e.g. lerobot_datasets, hdf5_datasets, dummy_datasets)."
},
)
dataset_path: Optional[str] = field(
default=None,
metadata={"help": "Filesystem path or repo id of the dataset to train on."},
)
dataset_strategy: Optional[str] = field(
default="default",
metadata={
"help": "Under --dataset-format lerobot_datasets: the model-specific "
"dataset build strategy ('default', 'fastwam', "
"'cosmos3_droid', or 'dreamzero'); unknown values fall back "
"to 'default'."
},
)
split: str = field(
default="train",
metadata={
"help": "Dataset split to load (RLDS), e.g. 'train' or 'train[:95%%]'."
},
)
lerobotdataset_version: str = field(
default="v3.0",
metadata={
"choices": ["v2.0", "v2.1", "v3.0"],
"help": "On-disk LeRobot dataset format version to parse.",
},
)
video_backend: str = field(
default="torchcodec",
metadata={
"choices": ["torchcodec", "decord", "opencv", "pyav", "torchvision_av"],
"help": "Backend used to decode episode videos into frames.",
},
)
streaming: bool = field(
default=False,
metadata={
"help": "Use a streaming/iterable dataset instead of map-style random "
"access (lower memory, no global shuffle)."
},
)
data_root_dir: Optional[str] = field(
default=None,
metadata={
"help": "Root directory containing the datasets referenced by "
"--dataset-mix."
},
)
robot_type: Optional[str] = field(
default=None,
metadata={
"help": "Robot embodiment type (e.g. libero_franka); selects "
"action/state layout."
},
)
task_name: str = field(
default="perform the task",
metadata={
"help": "Language instruction used as the prompt when the dataset has "
"none (HDF5)."
},
)
per_device_batch_size: int = field(
default=4,
metadata={"help": "Micro-batch size processed per GPU per forward pass."},
)
num_workers: int = field(
default=4,
metadata={"help": "Number of DataLoader worker processes per rank."})
dataloader_seed_workers: bool = field(
default=False,
metadata={"help": "Set DataLoader worker_init_fn and generator from --seed. "
"Default leaves both unset for baseline precision comparison."})
dataloader_multiprocessing_context: Optional[str] = field(
default=None,
metadata={
"choices": ["fork", "spawn", "forkserver"],
"help": "Multiprocessing start method for DataLoader workers.",
},
)
distributed_sampler_mode: str = field(
default="cyclic",
metadata={
"choices": ["cyclic", "block"],
"help": "How the distributed sampler partitions indices across ranks: "
"'cyclic' (round-robin) or 'block' (contiguous shards).",
},
)
batch_drop_last: bool = field(
default=False,
metadata={
"help": (
"If True, drop the last incomplete batch so every rank sees the same "
"number of full-size batches. Applied to both sampler and DataLoader. "
"Default False preserves all samples."
),
},
)
num_samples: int = field(
default=100,
metadata={
"help": "Number of synthetic samples to generate. Only effective "
"when --dataset-format=dummy_datasets."
},
)
@dataclass(frozen=True)
class _CheckpointArgs:
"""Checkpoint save/resume format and state."""
pretrained_checkpoint: Optional[str] = field(
default=None,
metadata={
"help": "Path to pretrained weights to initialize the model from "
"(fine-tuning)."
},
)
resume: bool = field(
default=False,
metadata={
"help": "Resume training (weights + optimizer/scheduler/RNG state) "
"from the latest checkpoint in --output-dir."
},
)
save_format: str = field(
default="safetensors",
metadata={
"choices": ["safetensors", "pt", "dcp"],
"help": "On-disk checkpoint format: safetensors, raw torch .pt, or "
"distributed checkpoint (dcp).",
},
)
save_training_state: bool = field(
default=True,
metadata={
"help": "Also save optimizer, LR scheduler, and RNG state (needed to "
"resume)."
},
)
async_save: bool = field(
default=False,
metadata={
"help": "Save checkpoints asynchronously in the background (dcp "
"format only)."
},
)
@dataclass(frozen=True)
class _FreezeArgs:
"""Parameter freezing by module path prefix."""
freeze_modules: str = field(
default="",
metadata={
"help": "Comma-separated module path prefixes whose parameters are "
"frozen (requires_grad=False)."
},
)
@dataclass(frozen=True)
class _LoraArgs:
"""LoRA/PEFT fine-tuning configuration."""
use_lora: bool = field(
default=False,
metadata={
"help": "Enable generic PEFT LoRA fine-tuning before distributed "
"wrapping. The model supplies default target modules."
},
)
lora_r: int = field(
default=16,
metadata={"help": "LoRA rank."},
)
lora_alpha: int = field(
default=32,
metadata={"help": "LoRA scaling alpha."},
)
lora_dropout: float = field(
default=0.0,
metadata={"help": "Dropout probability inside LoRA adapters."},
)
lora_target_modules: Optional[str] = field(
default=None,
metadata={
"help": "Comma-separated target module names. Overrides the "
"model-provided defaults."
},
)
lora_modules_to_save: Optional[str] = field(
default=None,
metadata={
"help": "Comma-separated modules trained and saved in full. "
"Overrides the model-provided defaults."
},
)
lora_bias: str = field(
default="none",
metadata={
"choices": ["none", "all", "lora_only"],
"help": "PEFT LoraConfig.bias policy.",
},
)
lora_init: str = field(
default="true",
metadata={
"help": "PEFT init_lora_weights mode, such as true, gaussian, or pissa."
},
)
@dataclass(frozen=True)
class _LoggingArgs:
"""Logging cadence, GC control, W&B, and TensorBoard."""
log_interval: int = field(
default=1,
metadata={
"help": "Log scalar metrics (loss, LR, throughput) every N iterations."
},
)
detail_log_interval: int = field(
default=20,
metadata={
"help": "Log detailed per-stage timing breakdown every N iterations."
},
)
timing_log_level: int = field(
default=0,
metadata={
"choices": [0, 1],
"help": "Verbosity of per-stage timing logs: 0 = summary, "
"1 = detailed.",
},
)
loss_log_rank: List[int] = field(
default_factory=lambda: [-1],
metadata={
"help": "Ranks whose loss is logged; -1 logs the all-reduced mean "
"across ranks."
},
)
wandb_project: str = field(
default="loongforge-vla",
metadata={"help": "Weights & Biases project name."},
)
wandb_mode: str = field(
default="disabled",
metadata={
"choices": ["online", "offline", "disabled"],
"help": "W&B logging mode: stream online, buffer offline, or disable.",
},
)
tensorboard_dir: Optional[str] = field(
default=None,
metadata={
"help": "Directory for TensorBoard event files; unset disables "
"TensorBoard."
},
)
tensorboard_queue_size: int = field(
default=1000,
metadata={
"help": "Max pending events buffered before the async TensorBoard "
"writer flushes."
},
)
@dataclass(frozen=True)
class _ProfilerArgs:
"""torch.profiler / Nsight profiling capture window."""
use_pytorch_profiler: bool = field(
default=False,
metadata={"help": "Enable torch.profiler to capture CPU/GPU op traces."},
)
use_nsys_profiler: bool = field(
default=False,
metadata={
"help": "Enable NVIDIA Nsight Systems (nsys) profiling range markers."
},
)
profile_step_start: int = field(
default=10,
metadata={"help": "Iteration at which profiling capture starts."},
)
profile_step_end: int = field(
default=12,
metadata={"help": "Iteration at which profiling capture stops."},
)
profile_ranks: List[int] = field(
default_factory=lambda: [0],
metadata={"help": "Ranks on which the profiler is active."},
)
profile_output_dir: Optional[str] = field(
default=None,
metadata={"help": "Directory to write profiler traces to."},
)
@dataclass(frozen=True)
class _CudaGraphArgs:
"""CUDA graph capture and manual gradient all-reduce."""
cuda_graph_impl: str = field(
default="none",
metadata={
"choices": ["none", "local"],
"help": "CUDA graph capture backend: 'none' disables, 'local' "
"captures the training step to cut per-step launch overhead.",
},
)
cuda_graph_scope: str = field(
default="full_iteration",
metadata={
"choices": ["full_iteration", "per_microbatch"],
"help": "What to capture into the graph: the whole iteration or "
"each micro-batch.",
},
)
cuda_graph_warmup_steps: int = field(
default=3,
metadata={
"help": "Number of eager (uncaptured) warmup iterations before "
"graph capture."
},
)
cuda_graph_pad_length: Optional[int] = field(
default=None,
metadata={
"help": "Fixed token sequence length to pad to; required so "
"captured shapes stay static across steps."
},
)
cuda_graph_ddp_sync_in_graph: bool = field(
default=False,
metadata={
"help": "Capture DDP gradient all-reduce inside the graph instead "
"of running it eagerly."
},
)
cuda_graph_grad_sync_bucket_mb: float = field(
default=200.0,
metadata={
"help": "Bucket size (MiB) for the manual gradient all-reduce used "
"with CUDA graphs."
},
)
cuda_graph_grad_sync_impl: str = field(
default="coalesced",
metadata={
"choices": ["flat", "coalesced"],
"help": "Manual gradient all-reduce implementation: single flat "
"buffer or coalesced buckets.",
},
)
cuda_graph_grad_sync_dtype: str = field(
default="fp32",
metadata={
"choices": ["fp32", "bf16"],
"help": "Communication dtype for the manual gradient all-reduce "
"(bf16 halves comm volume).",
},
)
@dataclass(frozen=True)
class _ActivationCheckpointArgs:
"""activation-checkpoint module selection."""
activation_checkpoint_module_patterns: Optional[str] = field(
default=None,
metadata={
"help": "Comma-separated qualified module-key patterns to wrap "
"with activation checkpointing. '*' matches one module-key "
"segment."
},
)
activation_checkpoint_skip_modules: Optional[str] = field(
default=None,
metadata={
"help": "Optional comma-separated qualified module keys to exclude "
"from --activation-checkpoint-module-patterns."
},
)
@dataclass(frozen=True)
class _DistributedArgs:
"""Parallelism strategy (FSDP/DDP), dtype, ZeRO, and meta-device init."""
init_on_meta: bool = field(
default=False,
metadata={"help": "Allocate all params on 'meta' device."
"Then weights are loaded into the sharded DTensors."
}
)
distributed_strategy: str = field(
default="fsdp",
metadata={
"choices": ["ddp", "fsdp"],
"help": "Parallelism strategy: DDP (replicate) or FSDP2 "
"(fully sharded).",
},
)
hsdp_shard_size: Optional[int] = field(
default=None,
metadata={
"cli_type": parse_positive_int,
"help": "Enable HSDP and set the second 2D mesh dimension size. "
"The first mesh dimension replicates parameters across "
"groups, and this dimension shards parameters within "
"each group. Must divide the distributed world size. "
"Unset uses regular 1D FSDP.",
},
)
fsdp_reshard_default: Any = field(
default=None,
metadata={
"cli_type": parse_reshard_after_forward,
"help": "Default FSDP2 reshard_after_forward policy: "
"true|false|none|int>1. Controls whether params are "
"re-sharded after forward to save memory.",
},