File size: 133,410 Bytes
462f951
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
"""See _CONFIGS for the list of available configs."""

import abc
from collections.abc import Sequence
import dataclasses
import difflib
import logging
import pathlib
from typing import Any, Literal, Protocol, TypeAlias

import etils.epath as epath
import flax.nnx as nnx
from typing_extensions import override
import tyro

import openpi.models.model as _model
import openpi.models.pi0_config as pi0_config
import openpi.models.pi0_fast as pi0_fast
import openpi.models.tokenizer as _tokenizer
import openpi.policies.aloha_policy as aloha_policy
import openpi.policies.b601_policy as b601_policy
import openpi.policies.droid_policy as droid_policy
import openpi.policies.libero_policy as libero_policy
import openpi.policies.ur3_policy as ur3_policy
import openpi.policies.ur3_bimanual_policy as ur3_bimanual_policy
import openpi.policies.unitree_policy as unitree_policy
import openpi.policies.unitree_eef_policy as unitree_eef_policy
import openpi.policies.unitree_eef6d_policy as unitree_eef6d_policy
import openpi.shared.download as _download
import openpi.shared.normalize as _normalize
import openpi.training.droid_rlds_dataset as droid_rlds_dataset
import openpi.training.misc.polaris_config as polaris_config
import openpi.training.misc.roboarena_config as roboarena_config
import openpi.training.optimizer as _optimizer
import openpi.training.weight_loaders as weight_loaders
import openpi.transforms as _transforms

ModelType: TypeAlias = _model.ModelType
# Work around a tyro issue with using nnx.filterlib.Filter directly.
Filter: TypeAlias = nnx.filterlib.Filter


@dataclasses.dataclass(frozen=True)
class AssetsConfig:
    """Determines the location of assets (e.g., norm stats) that will be used to set up the data pipeline.

    These assets will be replicated inside the checkpoint under the `assets/asset_id` directory.

    This can be used to load assets from a different checkpoint (e.g., base model checkpoint) or some other
    centralized location. For example, to load the norm stats for the Trossen robot from the base model checkpoint
    during fine-tuning, use:

    ```
    AssetsConfig(
        assets_dir="gs://openpi-assets/checkpoints/pi0_base/assets",
        asset_id="trossen",
    )
    ```
    """

    # Assets directory. If not provided, the config assets_dirs will be used. This is useful to load assets from
    # a different checkpoint (e.g., base model checkpoint) or some other centralized location.
    assets_dir: str | None = None

    # Asset id. If not provided, the repo id will be used. This allows users to reference assets that describe
    # different robot platforms.
    asset_id: str | None = None


@dataclasses.dataclass(frozen=True)
class DataConfig:
    # LeRobot repo id. If None, fake data will be created.
    repo_id: str | None = None
    # Directory within the assets directory containing the data assets.
    asset_id: str | None = None
    # Contains precomputed normalization stats. If None, normalization will not be performed.
    norm_stats: dict[str, _transforms.NormStats] | None = None

    # Used to adopt the inputs from a dataset specific format to a common format
    # which is expected by the data transforms.
    repack_transforms: _transforms.Group = dataclasses.field(default_factory=_transforms.Group)
    # Data transforms, typically include robot specific transformations. Will be applied
    # before the data is normalized. See `model.Observation` and `model.Actions` to learn about the
    # normalized data.
    data_transforms: _transforms.Group = dataclasses.field(default_factory=_transforms.Group)
    # Model specific transforms. Will be applied after the data is normalized.
    model_transforms: _transforms.Group = dataclasses.field(default_factory=_transforms.Group)
    # If true, will use quantile normalization. Otherwise, normal z-score normalization will be used.
    use_quantile_norm: bool = False

    # Names of keys that will be used by the data loader to generate the action sequence. The length of the
    # sequence is defined by the `action_horizon` field in the model config. This should be adjusted if your
    # LeRobot dataset is using different keys to represent the action.
    action_sequence_keys: Sequence[str] = ("actions",)

    # If true, will use the LeRobot dataset task to define the prompt.
    prompt_from_task: bool = False

    # Local root directory for LeRobot datasets stored on disk.
    # When set, LeRobotDataset loads from `local_root / repo_id` instead of
    # downloading from HuggingFace Hub.  Useful during development when the
    # dataset has not been uploaded yet.
    local_root: pathlib.Path | None = None

    # Only used for RLDS data loader (ie currently only used for DROID).
    rlds_data_dir: str | None = None
    # Action space for DROID dataset.
    action_space: droid_rlds_dataset.DroidActionSpace | None = None
    # List of datasets to sample from: name, version, weight, and optionally filter_dict_path
    datasets: Sequence[droid_rlds_dataset.RLDSDataset] = ()


class GroupFactory(Protocol):
    def __call__(self, model_config: _model.BaseModelConfig) -> _transforms.Group:
        """Create a group."""


@dataclasses.dataclass(frozen=True)
class ModelTransformFactory(GroupFactory):
    """Creates model transforms for standard pi0 models."""

    # If provided, will determine the default prompt that be used by the model.
    default_prompt: str | None = None

    def __call__(self, model_config: _model.BaseModelConfig) -> _transforms.Group:
        match model_config.model_type:
            case _model.ModelType.PI0:
                return _transforms.Group(
                    inputs=[
                        _transforms.InjectDefaultPrompt(self.default_prompt),
                        _transforms.ResizeImages(224, 224),
                        _transforms.TokenizePrompt(
                            _tokenizer.PaligemmaTokenizer(model_config.max_token_len),
                        ),
                        _transforms.PadStatesAndActions(model_config.action_dim),
                    ],
                )
            case _model.ModelType.PI05:
                assert isinstance(model_config, pi0_config.Pi0Config)
                return _transforms.Group(
                    inputs=[
                        _transforms.InjectDefaultPrompt(self.default_prompt),
                        _transforms.ResizeImages(224, 224),
                        _transforms.TokenizePrompt(
                            _tokenizer.PaligemmaTokenizer(model_config.max_token_len),
                            discrete_state_input=model_config.discrete_state_input,
                        ),
                        _transforms.PadStatesAndActions(model_config.action_dim),
                    ],
                )
            case _model.ModelType.PI0_FAST:
                tokenizer_cls = (
                    _tokenizer.FASTTokenizer
                    if model_config.fast_model_tokenizer is None
                    else model_config.fast_model_tokenizer
                )
                tokenizer_kwargs = (
                    {} if model_config.fast_model_tokenizer_kwargs is None else model_config.fast_model_tokenizer_kwargs
                )
                return _transforms.Group(
                    inputs=[
                        _transforms.InjectDefaultPrompt(self.default_prompt),
                        _transforms.ResizeImages(224, 224),
                        _transforms.TokenizeFASTInputs(
                            tokenizer_cls(model_config.max_token_len, **tokenizer_kwargs),
                        ),
                    ],
                    outputs=[
                        _transforms.ExtractFASTActions(
                            tokenizer_cls(model_config.max_token_len, **tokenizer_kwargs),
                            action_horizon=model_config.action_horizon,
                            action_dim=model_config.action_dim,
                        )
                    ],
                )


@dataclasses.dataclass(frozen=True)
class DataConfigFactory(abc.ABC):
    # The LeRobot repo id.
    repo_id: str = tyro.MISSING
    # Determines how the assets will be loaded.
    assets: AssetsConfig = dataclasses.field(default_factory=AssetsConfig)
    # Base config that will be updated by the factory.
    base_config: tyro.conf.Suppress[DataConfig | None] = None

    @abc.abstractmethod
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        """Create a data config."""

    def create_base_config(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repo_id = self.repo_id if self.repo_id is not tyro.MISSING else None
        asset_id = self.assets.asset_id or repo_id
        return dataclasses.replace(
            self.base_config or DataConfig(),
            repo_id=repo_id,
            asset_id=asset_id,
            norm_stats=self._load_norm_stats(epath.Path(self.assets.assets_dir or assets_dirs), asset_id),
            use_quantile_norm=model_config.model_type != ModelType.PI0,
        )

    def _load_norm_stats(self, assets_dir: epath.Path, asset_id: str | None) -> dict[str, _transforms.NormStats] | None:
        if asset_id is None:
            return None
        try:
            data_assets_dir = str(assets_dir / asset_id)
            norm_stats = _normalize.load(_download.maybe_download(data_assets_dir))
            logging.info(f"Loaded norm stats from {data_assets_dir}")
            return norm_stats
        except FileNotFoundError:
            logging.info(f"Norm stats not found in {data_assets_dir}, skipping.")
        return None


@dataclasses.dataclass(frozen=True)
class FakeDataConfig(DataConfigFactory):
    repo_id: str = "fake"

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        return DataConfig(repo_id=self.repo_id)


@dataclasses.dataclass(frozen=True)
class SimpleDataConfig(DataConfigFactory):
    # Factory for the data transforms.
    data_transforms: tyro.conf.Suppress[GroupFactory] = dataclasses.field(default_factory=GroupFactory)
    # Factory for the model transforms.
    model_transforms: tyro.conf.Suppress[GroupFactory] = dataclasses.field(default_factory=ModelTransformFactory)

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            data_transforms=self.data_transforms(model_config),
            model_transforms=self.model_transforms(model_config),
        )


@dataclasses.dataclass(frozen=True)
class LeRobotAlohaDataConfig(DataConfigFactory):
    # If true, will convert joint dimensions to deltas with respect to the current state before passing to the model.
    # Gripper dimensions will remain in absolute values.
    use_delta_joint_actions: bool = True
    # If provided, will be injected into the input data if the "prompt" key is not present.
    default_prompt: str | None = None
    # If true, this will convert the joint and gripper values from the standard Aloha space to
    # the space used by the pi internal runtime which was used to train the base model. People who
    # use standard Aloha data should set this to true.
    adapt_to_pi: bool = True

    # Repack transforms.
    repack_transforms: tyro.conf.Suppress[_transforms.Group] = dataclasses.field(
        default=_transforms.Group(
            inputs=[
                _transforms.RepackTransform(
                    {
                        "images": {"cam_high": "observation.images.top"},
                        "state": "observation.state",
                        "actions": "action",
                    }
                )
            ]
        )
    )
    # Action keys that will be used to read the action sequence from the dataset.
    action_sequence_keys: Sequence[str] = ("action",)

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        data_transforms = _transforms.Group(
            inputs=[aloha_policy.AlohaInputs(adapt_to_pi=self.adapt_to_pi)],
            outputs=[aloha_policy.AlohaOutputs(adapt_to_pi=self.adapt_to_pi)],
        )
        if self.use_delta_joint_actions:
            delta_action_mask = _transforms.make_bool_mask(6, -1, 6, -1)
            data_transforms = data_transforms.push(
                inputs=[_transforms.DeltaActions(delta_action_mask)],
                outputs=[_transforms.AbsoluteActions(delta_action_mask)],
            )

        model_transforms = ModelTransformFactory(default_prompt=self.default_prompt)(model_config)

        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=self.repack_transforms,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
            action_sequence_keys=self.action_sequence_keys,
        )


@dataclasses.dataclass(frozen=True)
class LeRobotLiberoDataConfig(DataConfigFactory):
    """
    This config is used to configure transforms that are applied at various parts of the data pipeline.
    For your own dataset, you can copy this class and modify the transforms to match your dataset based on the
    comments below.
    """

    extra_delta_transform: bool = False

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        # The repack transform is *only* applied to the data coming from the dataset,
        # and *not* during inference. We can use it to make inputs from the dataset look
        # as close as possible to those coming from the inference environment (e.g. match the keys).
        # Below, we match the keys in the dataset (which we defined in the data conversion script) to
        # the keys we use in our inference pipeline (defined in the inference script for libero).
        # For your own dataset, first figure out what keys your environment passes to the policy server
        # and then modify the mappings below so your dataset's keys get matched to those target keys.
        # The repack transform simply remaps key names here.
        repack_transform = _transforms.Group(
          inputs=[
            _transforms.RepackTransform(
              {
                "observation/image":       "observation.images.image",
                "observation/wrist_image": "observation.images.wrist_image",
                "observation/state":       "observation.state",
                "actions":                 "actions",
                "prompt":                  "prompt",
              }
            )
        ]
      )

        # The data transforms are applied to the data coming from the dataset *and* during inference.
        # Below, we define the transforms for data going into the model (``inputs``) and the transforms
        # for data coming out of the model (``outputs``) (the latter is only used during inference).
        # We defined these transforms in `libero_policy.py`. You can check the detailed comments there for
        # how to modify the transforms to match your dataset. Once you created your own transforms, you can
        # replace the transforms below with your own.
        data_transforms = _transforms.Group(
            inputs=[libero_policy.LiberoInputs(model_type=model_config.model_type)],
            outputs=[libero_policy.LiberoOutputs()],
        )

        # One additional data transform: pi0 models are trained on delta actions (relative to the first
        # state in each action chunk). IF your data has ``absolute`` actions (e.g. target joint angles)
        # you can uncomment the following line to convert the actions to delta actions. The only exception
        # is for the gripper actions which are always absolute.
        # In the example below, we would apply the delta conversion to the first 6 actions (joints) and
        # leave the 7th action (gripper) unchanged, i.e. absolute.
        # In Libero, the raw actions in the dataset are already delta actions, so we *do not* need to
        # apply a separate delta conversion (that's why it's commented out). Choose whether to apply this
        # transform based on whether your dataset uses ``absolute`` or ``delta`` actions out of the box.

        # LIBERO already represents actions as deltas, but we have some old Pi0 checkpoints that are trained with this
        # extra delta transform.
        if self.extra_delta_transform:
            delta_action_mask = _transforms.make_bool_mask(6, -1)
            data_transforms = data_transforms.push(
                inputs=[_transforms.DeltaActions(delta_action_mask)],
                outputs=[_transforms.AbsoluteActions(delta_action_mask)],
            )

        # Model transforms include things like tokenizing the prompt and action targets
        # You do not need to change anything here for your own dataset.
        model_transforms = ModelTransformFactory()(model_config)

        # We return all data transforms for training and inference. No need to change anything here.
        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
        )

@dataclasses.dataclass(frozen=True)
class LeRobotUnitreeG1DataConfig(DataConfigFactory):
    """Unitree G1 Dex1 bimanual dataset config.
    16-DoF: L_arm(7) + R_arm(7) + L_grip(1) + R_grip(1).
    Three cameras: left_high (base), left_wrist, right_wrist.

    Set action_dim=12 for G1_23 (5-DoF arms: L_arm(5) + R_arm(5) + L_grip + R_grip)."""

    action_dim: int = unitree_policy.ACTION_DIM

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repack_transform = _transforms.Group(
            inputs=[
                _transforms.RepackTransform(
                    {
                        "observation/image":             "observation.images.cam_left_high",
                        "observation/left_wrist_image":  "observation.images.cam_left_wrist",
                        "observation/right_wrist_image": "observation.images.cam_right_wrist",
                        "observation/state":             "observation.state",
                        "actions":                       "action",   # single, matches dataset
                        "prompt":                        "prompt",
                    }
                )
            ]
        )
        data_transforms = _transforms.Group(
            inputs=[unitree_policy.UnitreeG1Inputs(model_type=model_config.model_type)],
            outputs=[unitree_policy.UnitreeG1Outputs(action_dim=self.action_dim)],
        )
        model_transforms = ModelTransformFactory()(model_config)
        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
            action_sequence_keys=("action",),   # single
        )


@dataclasses.dataclass(frozen=True)
class LeRobotUnitreeG1EEFDataConfig(DataConfigFactory):
    """Unitree G1 Dex1 bimanual EEF-space dataset config.
    16-dim: L_eef xyz+quat(7) + R_eef xyz+quat(7) + L_grip(1) + R_grip(1),
    pelvis frame, quaternion order (qx, qy, qz, qw).
    Three cameras: left_high (base), left_wrist, right_wrist.

    If `delta_position_actions` is True, the two EEF POSITION triplets (dims
    0:3 and 7:10 of the 16-dim quaternion layout) are converted to deltas
    relative to the current state before the model, and added back after.
    Quaternions and grippers stay absolute (delta of a quaternion is not
    meaningful). Same spatial-generalization rationale as the 6D delta config;
    the on-robot client contract is unchanged (AbsoluteActions re-adds the
    current pose, so returned actions are still absolute quaternion poses)."""

    # Delta the L/R EEF position triplets (quaternions/grippers stay absolute).
    # Needs its own norm_stats -> use a distinct config name / assets dir.
    delta_position_actions: bool = False

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repack_transform = _transforms.Group(
            inputs=[
                _transforms.RepackTransform(
                    {
                        "observation/image":             "observation.images.cam_left_high",
                        "observation/left_wrist_image":  "observation.images.cam_left_wrist",
                        "observation/right_wrist_image": "observation.images.cam_right_wrist",
                        "observation/state":             "observation.state",
                        "actions":                       "action",   # single, matches dataset
                        "prompt":                        "prompt",
                    }
                )
            ]
        )
        input_transforms = [unitree_eef_policy.UnitreeG1EEFInputs(model_type=model_config.model_type)]
        output_transforms = [unitree_eef_policy.UnitreeG1EEFOutputs()]
        if self.delta_position_actions:
            # 16-dim quat layout: [Lpos(3) | Lquat(4) | Rpos(3) | Rquat(4) | Lgrip | Rgrip].
            # Delta only the two position triplets; quaternions and grippers absolute.
            pos_delta_mask = _transforms.make_bool_mask(3, -4, 3, -4, -2)
            input_transforms.append(_transforms.DeltaActions(pos_delta_mask))
            output_transforms.insert(0, _transforms.AbsoluteActions(pos_delta_mask))
        data_transforms = _transforms.Group(inputs=input_transforms, outputs=output_transforms)
        model_transforms = ModelTransformFactory()(model_config)
        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
            action_sequence_keys=("action",),   # single
        )


@dataclasses.dataclass(frozen=True)
class LeRobotUnitreeG1EEF6DDataConfig(DataConfigFactory):
    """Unitree G1 Dex1 bimanual EEF-space dataset config, 6D rotation action space.

    On disk the dataset is the same 16-dim quaternion layout as
    LeRobotUnitreeG1EEFDataConfig (L/R xyz+quat + grippers, pelvis frame). The
    data transform converts quat->6D on the way into the model (state + actions,
    so norm_stats are computed on the 20-dim 6D representation) and 6D->quat on
    the way out, so the on-robot client contract stays 16-dim quaternion.

    If `delta_position_actions` is True, the two EEF POSITION triplets (dims
    0:3 and 9:12 of the 20-dim 6D layout) are converted to deltas relative to
    the current state before the model, and added back after. Rotations (6D)
    and grippers stay absolute. This makes the trajectory largely independent
    of the robot's absolute standing pose / object position and is the
    single most effective change for spatial generalization when collection and
    deployment are NOT at fixed positions (see UMI / action-space studies).
    The on-robot client contract is unchanged: AbsoluteActions re-adds the
    current EEF pose, so the client still receives absolute quaternion poses."""

    # Convert the L/R EEF position triplets to delta actions (rotations/grippers
    # stay absolute). Requires its own norm_stats (delta action distribution
    # differs from absolute), so use a distinct config name / assets dir.
    delta_position_actions: bool = False
    # When delta_position_actions is True, restrict the delta to the HORIZONTAL
    # (x, y) axes and keep z ABSOLUTE. Rationale: delta helps the relative
    # approach/grasp (x, y) and is robust to absolute-frame bias, but on z it
    # loses the absolute-height reference and accumulates drift — bad for
    # stacking to a fixed top-of-stack height. So delta x,y (generalize the
    # approach) + absolute z (precise placement height) is the best of both.
    delta_horizontal_only: bool = False

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repack_transform = _transforms.Group(
            inputs=[
                _transforms.RepackTransform(
                    {
                        "observation/image":             "observation.images.cam_left_high",
                        "observation/left_wrist_image":  "observation.images.cam_left_wrist",
                        "observation/right_wrist_image": "observation.images.cam_right_wrist",
                        "observation/state":             "observation.state",
                        "actions":                       "action",   # single, matches dataset
                        "prompt":                        "prompt",
                    }
                )
            ]
        )
        input_transforms = [unitree_eef6d_policy.UnitreeG1EEF6DInputs(model_type=model_config.model_type)]
        output_transforms = [unitree_eef6d_policy.UnitreeG1EEF6DOutputs()]
        if self.delta_position_actions:
            # 20-dim 6D layout: [Lx Ly Lz | Lrot6d(6) | Rx Ry Rz | Rrot6d(6) | Lgrip | Rgrip].
            if self.delta_horizontal_only:
                # delta x,y only; z, rotation-6D, grippers absolute.
                pos_delta_mask = _transforms.make_bool_mask(2, -1, -6, 2, -1, -6, -2)
            else:
                # delta the full position triplets; rotation-6D and grippers absolute.
                pos_delta_mask = _transforms.make_bool_mask(3, -6, 3, -6, -2)
            # DeltaActions runs AFTER the quat->6D input transform (needs the 20-dim
            # state+actions); AbsoluteActions runs BEFORE the 6D->quat output transform
            # (must act on the 20-dim layout the mask indexes).
            input_transforms.append(_transforms.DeltaActions(pos_delta_mask))
            output_transforms.insert(0, _transforms.AbsoluteActions(pos_delta_mask))
        data_transforms = _transforms.Group(inputs=input_transforms, outputs=output_transforms)
        model_transforms = ModelTransformFactory()(model_config)
        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
            action_sequence_keys=("action",),   # single
        )


@dataclasses.dataclass(frozen=True)
class LeRobotUR3MergedDataConfig(DataConfigFactory):
    """UR3 merged dataset config. Same as LiberoDataConfig but with
    correct column names for UR3 merged dataset (action singular,
    observation.images.image / wrist_image)."""

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repack_transform = _transforms.Group(
            inputs=[
                _transforms.RepackTransform(
                    {
                        "observation/image":       "observation.images.fixed",
                        "observation/wrist_image": "observation.images.cam_wrist",
                        "observation/state":       "observation.state",
                        "actions":                 "action",     # single to match dataset
                        "prompt":                  "prompt",
                    }
                )
            ]
        )

        data_transforms = _transforms.Group(
            inputs=[libero_policy.LiberoInputs(model_type=model_config.model_type)],
            outputs=[libero_policy.LiberoOutputs()],
        )

        model_transforms = ModelTransformFactory()(model_config)

        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
            action_sequence_keys=("action",),  # single
        )

        
@dataclasses.dataclass(frozen=True)
class OldLeRobotUR3MergedDataConfig(DataConfigFactory):
    """UR3 merged dataset config. Same as LiberoDataConfig but with
    correct column names for UR3 merged dataset (action singular,
    observation.images.image / wrist_image)."""

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repack_transform = _transforms.Group(
            inputs=[
                _transforms.RepackTransform(
                    {
                        "observation/image":       "observation.images.fixed",
                        "observation/wrist_image": "observation.images.cam_wrist",
                        "observation/state":       "observation.state",
                        "actions":                 "action",     # single to mathc dataset
                        "prompt":                  "prompt",
                    }
                )
            ]
        )

        data_transforms = _transforms.Group(
            inputs=[libero_policy.LiberoInputs(model_type=model_config.model_type)],
            outputs=[libero_policy.LiberoOutputs()],
        )

        model_transforms = ModelTransformFactory()(model_config)

        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
            action_sequence_keys=("action",),  # ← 单数,匹配数据集
        )



@dataclasses.dataclass(frozen=True)
class LeRobotB601DataConfig(DataConfigFactory):
    """Data config for fine-tuning on a Seeed B601 (single-arm follower) LeRobot v2.1 dataset.

    The B601 dataset stores a 7-dim absolute-joint-position state/action vector (degrees) and only two
    cameras (top, wrist); b601_policy zero-fills and masks the third view. Actions are *absolute* joint
    positions, so we do NOT apply a delta transform.
    """

    # Injected as the prompt for every sample. Leave None to take the prompt from the dataset's tasks.jsonl.
    default_prompt: str | None = None

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        # Remap raw LeRobot column names to the flat keys expected by B601Inputs (and by the inference client).
        repack_transform = _transforms.Group(
            inputs=[
                _transforms.RepackTransform(
                    {
                        "observation/top": "observation.images.top",
                        "observation/wrist": "observation.images.wrist",
                        "observation/state": "observation.state",
                        "actions": "action",
                        # PromptFromLeRobotTask runs before repack and repack drops unlisted keys, so the
                        # prompt has to be carried through explicitly when prompt_from_task is set.
                        "prompt": "prompt",
                    }
                )
            ]
        )

        data_transforms = _transforms.Group(
            inputs=[b601_policy.B601Inputs(model_type=model_config.model_type)],
            outputs=[b601_policy.B601Outputs()],
        )

        model_transforms = ModelTransformFactory(default_prompt=self.default_prompt)(model_config)

        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
        )


@dataclasses.dataclass(frozen=True)
class LeRobotRM65DataConfig(DataConfigFactory):
    """Data config for fine-tuning on the RealMan RM65 right-arm LeRobot v2.1 dataset.

    Same layout as B601 -- 7-dim state/action (right_q1..q6 in rad, right_gripper 0=closed..100=open)
    and two cameras (top, wrist) -- so the B601 policy transforms are reused as-is. Unlike B601,
    observation.state and action share one coordinate convention, so the joint actions can be
    trained as deltas relative to the current state.
    """

    # Injected as the prompt for every sample. Leave None to take the prompt from the dataset's tasks.jsonl.
    default_prompt: str | None = None
    # Train the 6 joints as deltas relative to the current state; the gripper stays absolute.
    use_delta_joint_actions: bool = False

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repack_transform = _transforms.Group(
            inputs=[
                _transforms.RepackTransform(
                    {
                        "observation/top": "observation.images.top",
                        "observation/wrist": "observation.images.wrist",
                        "observation/state": "observation.state",
                        "actions": "action",
                        "prompt": "prompt",
                    }
                )
            ]
        )

        data_transforms = _transforms.Group(
            inputs=[b601_policy.B601Inputs(model_type=model_config.model_type)],
            outputs=[b601_policy.B601Outputs()],
        )
        if self.use_delta_joint_actions:
            delta_action_mask = _transforms.make_bool_mask(6, -1)
            data_transforms = data_transforms.push(
                inputs=[_transforms.DeltaActions(delta_action_mask)],
                outputs=[_transforms.AbsoluteActions(delta_action_mask)],
            )

        model_transforms = ModelTransformFactory(default_prompt=self.default_prompt)(model_config)

        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
        )


@dataclasses.dataclass(frozen=True)
class RLDSDroidDataConfig(DataConfigFactory):
    """
    Config for training on DROID, using RLDS data format (for efficient training on larger datasets).
    """

    rlds_data_dir: str | None = None
    action_space: droid_rlds_dataset.DroidActionSpace | None = None

    # Filtering options. Can pass a path to a dictionary that maps episodes to timestep ranges
    # to tuples denoting ranges of time steps to keep (start, end). Episodes are uniquely identified with
    # f"{recording_folderpath}--{file_path}", both of which are present in the RLDS episode metadata.

    # List of datasets to sample from: name, version, weight, and optionally filter_dict_path
    datasets: Sequence[droid_rlds_dataset.RLDSDataset] = (
        droid_rlds_dataset.RLDSDataset(
            name="droid",
            version="1.0.1",
            weight=1.0,
            filter_dict_path="gs://openpi-assets/droid/droid_sample_ranges_v1_0_1.json",
        ),
    )

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repack_transform = _transforms.Group(
            inputs=[
                _transforms.RepackTransform(
                    {
                        "observation/exterior_image_1_left": "observation/image",
                        "observation/wrist_image_left": "observation/wrist_image",
                        "observation/joint_position": "observation/joint_position",
                        "observation/gripper_position": "observation/gripper_position",
                        "actions": "actions",
                        "prompt": "prompt",
                    }
                )
            ]
        )

        data_transforms = _transforms.Group(
            inputs=[droid_policy.DroidInputs(model_type=model_config.model_type)],
            outputs=[droid_policy.DroidOutputs()],
        )

        if self.action_space == droid_rlds_dataset.DroidActionSpace.JOINT_POSITION:
            # Data loader returns absolute joint position actions -- convert to delta actions for training.
            delta_action_mask = _transforms.make_bool_mask(7, -1)
            data_transforms = data_transforms.push(
                inputs=[_transforms.DeltaActions(delta_action_mask)],
                outputs=[_transforms.AbsoluteActions(delta_action_mask)],
            )

        model_transforms = ModelTransformFactory()(model_config)

        assert self.rlds_data_dir is not None, "Need to set rlds data dir for RLDS data loader."

        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
            rlds_data_dir=self.rlds_data_dir,
            action_space=self.action_space,
            datasets=self.datasets,
        )


@dataclasses.dataclass(frozen=True)
class LeRobotDROIDDataConfig(DataConfigFactory):
    """
    Example data config for custom DROID dataset in LeRobot format.
    To convert your custom DROID dataset (<10s of hours) to LeRobot format, see examples/droid/convert_droid_data_to_lerobot.py
    """

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repack_transform = _transforms.Group(
            inputs=[
                _transforms.RepackTransform(
                    {
                        "observation/exterior_image_1_left": "exterior_image_1_left",
                        "observation/exterior_image_2_left": "exterior_image_2_left",
                        "observation/wrist_image_left": "wrist_image_left",
                        "observation/joint_position": "joint_position",
                        "observation/gripper_position": "gripper_position",
                        "actions": "actions",
                        "prompt": "prompt",
                    }
                )
            ]
        )
        # We assume joint *velocity* actions, so we should *not* apply an additional delta transform.
        data_transforms = _transforms.Group(
            inputs=[droid_policy.DroidInputs(model_type=model_config.model_type)],
            outputs=[droid_policy.DroidOutputs()],
        )
        model_transforms = ModelTransformFactory()(model_config)

        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
        )

@dataclasses.dataclass(frozen=True)
class LeRobotUR3DataConfig(DataConfigFactory):

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repack_transform = _transforms.Group(
            inputs=[_transforms.RepackTransform(ur3_policy.REPACK_STRUCTURE)]
        )
        data_transforms = _transforms.Group(
            inputs=[ur3_policy.UR3Inputs(model_type=model_config.model_type)],
            outputs=[ur3_policy.UR3Outputs()],
        )
        # Actions are absolute joint positions → convert to delta for training.
        # Gripper (last dim) stays absolute, hence -1 at the end.
        delta_action_mask = _transforms.make_bool_mask(6, -1)
        data_transforms = data_transforms.push(
            inputs=[_transforms.DeltaActions(delta_action_mask)],
            outputs=[_transforms.AbsoluteActions(delta_action_mask)],
        )
        model_transforms = ModelTransformFactory()(model_config)
        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
        )


@dataclasses.dataclass(frozen=True)
class LeRobotUR3BimanualDataConfig(DataConfigFactory):
    """Dual-arm UR3 (14-dim: per arm 6 joints + gripper, 3 cameras), see ur3_bimanual_policy."""

    @override
    def create(self, assets_dirs: pathlib.Path, model_config: _model.BaseModelConfig) -> DataConfig:
        repack_transform = _transforms.Group(
            inputs=[_transforms.RepackTransform(ur3_bimanual_policy.REPACK_STRUCTURE)]
        )
        data_transforms = _transforms.Group(
            inputs=[ur3_bimanual_policy.UR3BimanualInputs(model_type=model_config.model_type)],
            outputs=[ur3_bimanual_policy.UR3BimanualOutputs()],
        )
        # Actions are absolute joint positions -> delta for training; both grippers stay absolute.
        delta_action_mask = _transforms.make_bool_mask(6, -1, 6, -1)
        data_transforms = data_transforms.push(
            inputs=[_transforms.DeltaActions(delta_action_mask)],
            outputs=[_transforms.AbsoluteActions(delta_action_mask)],
        )
        model_transforms = ModelTransformFactory()(model_config)
        return dataclasses.replace(
            self.create_base_config(assets_dirs, model_config),
            repack_transforms=repack_transform,
            data_transforms=data_transforms,
            model_transforms=model_transforms,
            action_sequence_keys=("action",),
        )



@dataclasses.dataclass(frozen=True)
class TrainConfig:
    # Name of the config. Must be unique. Will be used to reference this config.
    name: tyro.conf.Suppress[str]
    # Project name.
    project_name: str = "openpi"
    # Experiment name. Will be used to name the metadata and checkpoint directories.
    exp_name: str = tyro.MISSING

    # Defines the model config. Some attributes (action_dim, action_horizon, and max_token_len) are shared by all models
    # -- see BaseModelConfig. Specific model implementations (e.g., Pi0Config) inherit from BaseModelConfig and may
    # define additional attributes.
    model: _model.BaseModelConfig = dataclasses.field(default_factory=pi0_config.Pi0Config)

    # A weight loader can optionally load (possibly partial) weights from disk after the model is initialized.
    weight_loader: weight_loaders.WeightLoader = dataclasses.field(default_factory=weight_loaders.NoOpWeightLoader)

    # Optional path to a PyTorch checkpoint to load weights from.
    pytorch_weight_path: str | None = None

    # Precision for PyTorch training.
    pytorch_training_precision: Literal["bfloat16", "float32"] = "bfloat16"

    lr_schedule: _optimizer.LRScheduleConfig = dataclasses.field(default_factory=_optimizer.CosineDecaySchedule)
    optimizer: _optimizer.OptimizerConfig = dataclasses.field(default_factory=_optimizer.AdamW)
    ema_decay: float | None = 0.99

    # Specifies which weights should be frozen.
    freeze_filter: tyro.conf.Suppress[Filter] = dataclasses.field(default_factory=nnx.Nothing)

    # Determines the data to be trained on.
    data: DataConfigFactory = dataclasses.field(default_factory=FakeDataConfig)

    # Base directory for config assets (e.g., norm stats).
    assets_base_dir: str = "./assets"
    # Base directory for checkpoints.
    checkpoint_base_dir: str = "./checkpoints"

    # Random seed that will be used by random generators during training.
    seed: int = 42
    # Global batch size.
    batch_size: int = 32
    # Number of workers to use for the data loader. Increasing this number will speed up data loading but
    # will increase memory and CPU usage.
    num_workers: int = 2
    # Number of train steps (batches) to run.
    num_train_steps: int = 30_000

    # How often (in steps) to log training metrics.
    log_interval: int = 100
    # How often (in steps) to save checkpoints.
    save_interval: int = 1000
    # If set, any existing checkpoints matching step % keep_period == 0 will not be deleted.
    keep_period: int | None = 5000

    # If true, will overwrite the checkpoint directory if it already exists.
    overwrite: bool = False
    # If true, will resume training from the last checkpoint.
    resume: bool = False

    # If true, will enable wandb logging.
    wandb_enabled: bool = True

    # Used to pass metadata to the policy server.
    policy_metadata: dict[str, Any] | None = None

    # If the value is greater than 1, FSDP will be enabled and shard across number of specified devices; overall
    # device memory will be reduced but training could potentially be slower.
    # eg. if total device is 4 and fsdp devices is 2; then the model will shard to 2 devices and run
    # data parallel between 2 groups of devices.
    fsdp_devices: int = 1

    # --- Periodic open-loop eval (used by scripts/train_eval.py) ---
    # How often (in steps) to run eval. 0 disables eval.
    eval_interval: int = 0
    # Number of episodes (from the start of the dataset) to evaluate.
    eval_episodes: int = 1
    # Evaluate every Nth frame within an episode.
    eval_stride: int = 1
    # Optional cap on the number of frames evaluated per episode.
    eval_max_frames: int | None = None
    # Dataset directory for eval. If None, uses the training dataset.
    eval_data_path: str | None = None

    @property
    def assets_dirs(self) -> pathlib.Path:
        """Get the assets directory for this config."""
        return (pathlib.Path(self.assets_base_dir) / self.name).resolve()

    @property
    def checkpoint_dir(self) -> pathlib.Path:
        """Get the checkpoint directory for this config."""
        if not self.exp_name:
            raise ValueError("--exp_name must be set")
        return (pathlib.Path(self.checkpoint_base_dir) / self.name / self.exp_name).resolve()

    @property
    def trainable_filter(self) -> nnx.filterlib.Filter:
        """Get the filter for the trainable parameters."""
        return nnx.All(nnx.Param, nnx.Not(self.freeze_filter))

    def __post_init__(self) -> None:
        if self.resume and self.overwrite:
            raise ValueError("Cannot resume and overwrite at the same time.")

#modify here lyh
# Use `get_config` if you need to get a config by name in your code.
_CONFIGS = [
    #
    # Inference Aloha configs.
    #
    TrainConfig(
        name="pi05_libero_ur3",
        #model=pi0_config.Pi0Config(pi05=True, action_horizon=10, discrete_state_input=False, paligemma_variant="gemma_2b_lora", action_expert_variant="gemma_300m_lora"),
        model=pi0_config.Pi0Config(pi05=True, action_horizon=10, discrete_state_input=False, paligemma_variant="gemma_2b_lora", action_expert_variant="gemma_300m_lora"),
        data=LeRobotLiberoDataConfig(
            repo_id="/home/ur3-exp/pi/outcomes/tmp/ur3-pink-cylinder_6D_final/",
            base_config=DataConfig(prompt_from_task=True),
            extra_delta_transform=False,
#            assets=AssetsConfig(
#              assets_dir="/home/ur3-exp/pi/openpi/assets",   # 本地目录
#              asset_id="ur3_pick_place",                      # 自己起个名
#    ),
        ),
        batch_size=64,
        freeze_filter=pi0_config.Pi0Config(
            paligemma_variant="gemma_2b_lora", action_expert_variant="gemma_300m_lora"
        ).get_freeze_filter(),
        ema_decay=None,
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        num_train_steps=1500,
        keep_period=250,
        save_interval=250,
    ),
    
    TrainConfig(
    # Unitree G1 Dex1 bimanual pick-and-place, 16-DoF.
    # T2 strategy: PaliGemma LoRA + Action Expert full fine-tuning.
    # Small dataset (~20k frames, 50 eps) → smaller bs, fewer steps than UR3 5task.
      name="pi05_unitree_g1",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=32,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1DataConfig(
        repo_id="stack-cube-new",
        base_config=DataConfig(
            local_root=pathlib.Path("/home/ur3-exp/unitree/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),

      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
    #   keep_last=3,
      keep_period=2000,
    #   fsdp_devices=4,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
          # How often (in steps) to run eval. 0 disables eval.
    eval_interval = 500,
    # Number of episodes (from the start of the dataset) to evaluate.
    eval_episodes = 5,
    # Evaluate every Nth frame within an episode.
    eval_stride= 20,
    # Optional cap on the number of frames evaluated per episode.
    eval_max_frames = None,
    # Dataset directory for eval. If None, uses the training dataset.
    eval_data_path = "/home/ur3-exp/unitree/data/stack-cube-new-eval",

    ),

    TrainConfig(
    # Serving alias for checkpoints/pi05_g1_eef/v1 (hang-tool, trained 2026-07-28,
    # wandb k6xv7l34). That run used pi05_g1_eef with repo_id="hang-tool-eef";
    # pi05_g1_eef has since been repointed to stack-cube-eef, so serving v1 under
    # that name looks up the wrong norm stats. Identical recipe otherwise.
    # Serve with --policy.config=pi05_g1_hang_tool --policy.dir=checkpoints/pi05_g1_eef/v1/19999
      name="pi05_g1_hang_tool",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=32,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEFDataConfig(
        repo_id="hang-tool-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
    ),

    TrainConfig(
    # Unitree G1 Dex1 bimanual pick-and-place, EEF action space.
    # Same recipe as pi05_unitree_g1 but state/action are EEF poses
    # (L/R xyz+quat + grippers, 16-dim) converted by ~/unitree/data/joint_to_eef.py.
    # T2 strategy: PaliGemma LoRA + Action Expert full fine-tuning.
      name="pi05_g1_eef",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=32,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEFDataConfig(
        repo_id="stack-cube-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
    #   weight_loader=weight_loaders.CheckpointWeightLoader("/home/ur3-exp/pi/openpi/checkpoints/pi05_g1_eef/eef_v1/19999/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
    # item-classification has no separate eval split; None -> eval on the training dataset.
      eval_data_path = None,
    ),
    TrainConfig(
    # Unitree G1 Dex1 bimanual pick-and-place, EEF action space.
    # Same recipe as pi05_unitree_g1 but state/action are EEF poses
    # (L/R xyz+quat + grippers, 16-dim) converted by ~/unitree/data/joint_to_eef.py.
    # T2 strategy: PaliGemma LoRA + Action Expert full fine-tuning.
      name="pi05_g1_eef2",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=32,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEFDataConfig(
        repo_id="stack-v3-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
    #   weight_loader=weight_loaders.CheckpointWeightLoader("/home/ur3-exp/pi/openpi/checkpoints/pi05_g1_eef/eef_v1/19999/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
      eval_data_path = "/shared/user64/workspace/yuhao/pi/data/sort-tools-mered-eef-eval",
    ),
    TrainConfig(
    # Unitree G1 Dex1 bimanual block-stacking, EEF pose action space with a 6D
    # rotation representation (see unitree_eef6d_policy.py). Same recipe as
    # pi05_g1_eef; the ONLY difference is quat->6D on model in/out, which
    # removes the quaternion double-cover ambiguity that made the left-arm
    # orientation the worst-tracked channel. On-disk data stays 16-dim quat.
    # Trains on stack-merged-eef (stack-cube-eef + stack-the-cube-v2-eef merged,
    # both relabeled to the color-stacking prompt).
      name="pi05_g1_eef6d",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="stack-merged-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/home/ur3-exp/unitree/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
      eval_data_path = "/home/ur3-exp/unitree/data/stack-cube-new-eval-eef",
    ),

    TrainConfig(
    # Same as pi05_g1_eef6d, but the two EEF position triplets are DELTA actions
    # (relative to the current EEF pose); rotations (6D) and grippers stay
    # absolute. Highest-leverage change for spatial generalization when object /
    # robot positions vary between collection and deployment (delta trajectories
    # are largely independent of absolute start pose). Needs its OWN norm_stats
    # (delta action distribution differs) -> distinct config name / assets dir.
    # Client contract is unchanged: AbsoluteActions re-adds the current pose, so
    # the returned actions are still absolute quaternion poses.
      name="pi05_g1_eef6d_delta",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="stack-merged-eef",
        delta_position_actions=True,
        base_config=DataConfig(
            local_root=pathlib.Path("/home/ur3-exp/unitree/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
      eval_data_path = "/home/ur3-exp/unitree/data/stack-cube-eval-eef",
    ),

    TrainConfig(
    # VARIABLE-ISOLATION configs: identical recipe to pi05_g1_eef6d(_delta) but
    # trained on stack-cube-eef ONLY (95 eps, correct stacking prompt), NOT the
    # merged set. Use these to disentangle whether the "grasp-then-oscillate"
    # regression is caused by (a) the added stack-the-cube-v2 data (conflicting
    # placement height) or (b) the delta representation:
    #   pi05_g1_eef6d_scube        : 6D absolute, stack-cube-eef only
    #   pi05_g1_eef6d_delta_scube  : 6D + position-delta, stack-cube-eef only
    # If _scube places cleanly and the merged model does not -> v2 is the cause.
    # If _delta_scube oscillates but _scube does not -> delta feedback is the cause.
      name="pi05_g1_eef6d_scube",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="stack-cube-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/home/ur3-exp/unitree/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
      eval_data_path = "/home/ur3-exp/unitree/data/stack-cube-eval-eef",
    ),

    TrainConfig(
    # 6D + position-delta, stack-cube-eef ONLY. See pi05_g1_eef6d_scube header.
      name="pi05_g1_eef6d_delta_scube",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="stack-cube-eef",
        delta_position_actions=True,
        base_config=DataConfig(
            local_root=pathlib.Path("/home/ur3-exp/unitree/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
      eval_data_path = "/home/ur3-exp/unitree/data/stack-cube-eval-eef",
    ),

    TrainConfig(
    # 7D (quaternion) EEF representation + position-delta, stack-cube-eef ONLY.
    # Same as pi05_g1_eef6d_delta_scube but keeps the ORIGINAL 16-dim quaternion
    # action space (L/R xyz+quat + grippers) instead of 6D rotation. Position
    # triplets are delta; quaternions and grippers stay absolute. Use it to
    # isolate the effect of the delta representation on your known-good 7D setup,
    # and to compare 7D-delta vs 6D-delta head to head.
      name="pi05_g1_eef_delta_scube",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEFDataConfig(
        repo_id="stack-cube-eef",
        delta_position_actions=True,
        base_config=DataConfig(
            local_root=pathlib.Path("/home/ur3-exp/unitree/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
      eval_data_path = "/home/ur3-exp/unitree/data/stack-cube-new-eval-eef",
    ),

    TrainConfig(
    # MIXED action space: 6D, position-delta on x,y only, z/rotation/grippers
    # ABSOLUTE. Motivated by the empirical split observed on the robot:
    #   - full-delta improved GRASP precision (relative approach on x,y, robust
    #     to absolute-frame bias, closed-loop convergence) but
    #   - full-delta learned HEIGHT poorly (delta loses the absolute-z reference
    #     and accumulates drift -> bad for stacking to a fixed top-of-stack z).
    # Delta x,y keeps the grasp benefit; absolute z restores placement-height
    # precision. Rotation (6D) and grippers stay absolute. stack-cube-eef only.
      name="pi05_g1_eef6d_deltaxy_scube",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="stack-cube-eef",
        delta_position_actions=True,
        delta_horizontal_only=True,
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
      eval_data_path = "/shared/user64/workspace/yuhao/pi/data/stack-cube-eef-eval",
    ),
    TrainConfig(
    # Unitree G1 Dex1 bimanual color-matching, EEF pose action space with 6D
    # rotation (same recipe as pi05_g1_eef6d). Trains on biomanual-eef
    # (LGG100/biomanual, 50 eps / 19951 frames, converted by
    # scripts/joint_to_eef.py). Task: put each cup on the coaster of the same
    # color, blue first and then green onto the coaster the blue cup vacated; the
    # two arms act in sequence rather than together (measured gripper overlap is
    # 0.000 across all 50 episodes), and the layout is randomized per episode.
    #
    # Steps: at batch_size 32 this set is 623 step/epoch, so 20000 steps is ~32
    # epochs. pi05_g1_tennis and pi05_g1_simple_pick use the same 20000 on sets of
    # nearly identical size (19008 / 18463 frames), which keeps the three directly
    # comparable; pi05_g1_drawer keeps the same step budget but on 2.4x the data,
    # so it sees only ~13 epochs -- this family is step-matched, not epoch-matched.
      name="pi05_g1_biomanual",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="biomanual-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
    # No separate eval split; None -> open-loop eval on the training dataset.
      eval_data_path = None,
    ),
    TrainConfig(
    # Unitree G1 Dex1 bimanual drawer task, EEF pose action space with 6D
    # rotation (same recipe as pi05_g1_eef6d). Trains on drawer-eef
    # (LGG100/drawer, 100 eps / 47741 frames, converted by
    # scripts/joint_to_eef.py). Task: the arm nearer to the drawer pulls it open,
    # the other puts the purple cube inside, then the drawer is closed -- a long,
    # sequential two-arm episode (~477 frames avg), hence the 48-step chunk.
    #
    # Steps: at batch_size 32 this set is 1492 step/epoch, so 20000 steps is only
    # ~13 epochs -- the same step budget as the other three G1 EEF tasks but 2.4x
    # the data, so proportionally far less exposure per episode. Raise to ~45000
    # if you want epoch parity with them; left at 20000 so the four runs cost the
    # same and stay comparable step-for-step.
      name="pi05_g1_drawer",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="drawer-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
    # No separate eval split; None -> open-loop eval on the training dataset.
      eval_data_path = None,
    ),
    TrainConfig(
    # Unitree G1 Dex1 tennis-ball-into-tube, EEF pose action space with 6D rotation
    # (same recipe as pi05_g1_biomanual / pi05_g1_drawer). Trains on tennis-eef
    # (51 eps / 19008 frames, converted by scripts/joint_to_eef.py). Task: one arm
    # holds the ball tube while the other drops a tennis ball in, then the tube is
    # stood upright on the empty coaster -- asymmetric bimanual, one arm keeps a
    # static grasp for most of the episode.
    #
    # Steps: at batch_size 32 this set is 594 step/epoch, so 20000 steps is ~34
    # epochs -- the same budget pi05_g1_biomanual gets on a set of nearly identical
    # size (19951 frames, 623 step/epoch, ~32 epochs), which keeps the two directly
    # comparable. save_interval 4000 + keep_period 2000 leave intermediate
    # checkpoints to fall back on if it overfits.
      name="pi05_g1_tennis",
      model=pi0_config.Pi0Config(
        pi05=True,
        # 48 covers ~13% of a 373-frame episode here, matching biomanual/drawer.
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="tennis-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
    # No separate eval split; None -> open-loop eval on the training dataset.
      eval_data_path = None,
    ),
    TrainConfig(
    # Unitree G1 Dex1 single-arm pick-and-drop, EEF pose action space with 6D
    # rotation (same recipe as pi05_g1_biomanual / pi05_g1_drawer). Trains on
    # simple-pick-eef (91 eps / 18463 frames, converted by scripts/joint_to_eef.py).
    # Task: pick the pink cube up with the nearer arm and drop it into the green
    # bin -- the simplest set of this family, one reach-grasp-drop and no second
    # phase.
    #
    # action_horizon is 32 here rather than the 48 the other three G1 EEF tasks use:
    # episodes run 144-286 frames (mean 202), about half of tennis-eef's and a
    # third of drawer-eef's, so a 48-step chunk would span a quarter of a whole
    # episode and pad heavily near the end. 32 matches pi05_g1_eef.
    #
    # Steps: at batch_size 32 this set is 577 step/epoch, so 20000 steps is ~35
    # epochs -- same budget as the sibling tasks. If it overfits (the likeliest of
    # the four, being the simplest), compare the 12000/14000/16000 checkpoints
    # before shortening the schedule.
      name="pi05_g1_simple_pick",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=32,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="simple-pick-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
    # No separate eval split; None -> open-loop eval on the training dataset.
      eval_data_path = None,
    ),
    TrainConfig(
    # Unitree G1_23 Dex1 (real robot, 5-DoF arms) "pick up the leftmost X bottle",
    # JOINT action space, 12-dim: L_arm(5) + R_arm(5) + L_grip + R_grip. Trains on
    # pick-leftmost-g1-23 (181 eps / 50699 frames): the four v3.0 sets from
    # pick_leftmost_g1_23_dex1_lerobot_only_20260922 (cola, water, two hand-soap
    # sessions -> 3 prompts) merged to v2.1 by scripts/convert_g1_23_v30_to_v21.py,
    # with handsoap_094922Z ep28 dropped (right arm sagged, state diverged from
    # action). Left-arm-only task; the right arm and gripper barely move.
    #
    # Not interchangeable with the G1_29 configs above: different arm DoF and a
    # real-robot camera setup, so initialise from pi05_base, not from those runs.
    #
    # Episodes run 145-586 frames (mean 280), so action_horizon 32 as in
    # pi05_g1_simple_pick. At batch_size 32 this is ~1584 step/epoch, so 20000
    # steps is ~12.6 epochs -- the pi05_g1_drawer budget on a set of similar size.
      name="pi05_g1_23_pick_leftmost",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=32,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1DataConfig(
        repo_id="pick-leftmost-g1-23",
        action_dim=12,
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
    # No separate eval split; None -> open-loop eval on the training dataset.
      eval_data_path = None,
    ),
    TrainConfig(
    # Unitree G1_23 Dex1 "pick up the leftmost X", v2 collection: same robot, action
    # space and recipe as pi05_g1_23_pick_leftmost, but a new scene (shelf instead of
    # table) and a different initial arm pose, so it trains on v2 alone from pi05_base.
    # pick-leftmost-v2-g1-23 (251 eps / 96200 frames): the raw sessions in
    # pickup_leftmost_v2_g1_23_20261001 (chips can 131, cola 120 -> 2 prompts)
    # converted by scripts/convert_g1_23_raw_to_v21.py, no episodes dropped.
    # Left-arm-only task; the right arm is held still. 42 episodes (chips can
    # ep72-112, cola ep111) keep the right gripper half closed throughout -- kept.
    #
    # Episodes run 205-576 frames (mean 383). At batch_size 32 this is ~3006
    # step/epoch, so 20000 steps is ~6.7 epochs.
      name="pi05_g1_23_pick_leftmost_v2",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=32,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1DataConfig(
        repo_id="pick-leftmost-v2-g1-23",
        action_dim=12,
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
    # No separate eval split; None -> open-loop eval on the training dataset.
      eval_data_path = None,
    ),
    TrainConfig(
    # Unitree G1_23 Dex1 "place the X bottle at the red X", same robot, action
    # space and recipe as pi05_g1_23_pick_leftmost. Trains on place-at-red-x-g1-23
    # (99 eps / 22091 frames): the four v3.0 sets from
    # place_at_red_x_g1_23_dex1_lerobot_only_20260923 (two cola sessions, hand
    # soap, water -> 3 prompts) merged by scripts/convert_g1_23_v30_to_v21.py, no
    # episodes dropped. Every episode starts with the bottle already in the closed
    # left gripper and opens it once at ~60% -- the place half of pick-and-place.
    #
    # Episodes run 128-389 frames (mean 223), so action_horizon 32. At batch_size
    # 32 this is ~690 step/epoch, so 20000 steps is ~29 epochs, close to
    # pi05_g1_simple_pick's ~35 on a set of similar size; if it overfits, compare
    # the 12000/16000 checkpoints before shortening the schedule.
      name="pi05_g1_23_place_red_x",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=32,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1DataConfig(
        repo_id="place-at-red-x-g1-23",
        action_dim=12,
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
    # No separate eval split; None -> open-loop eval on the training dataset.
      eval_data_path = None,
    ),
    TrainConfig(
    # Unitree G1 Dex1 three-colour sorting, EEF pose action space with 6D rotation
    # (same recipe as pi05_g1_biomanual / pi05_g1_drawer). Trains on
    # item-classification-new-eef (100 eps / 66933 frames). Task: red object into
    # the red box, then blue into blue, then yellow into yellow -- three sequential
    # pick-and-places, the longest episodes of this family (486-881 frames, mean
    # 669, vs 477 for drawer).
    #
    # The prompt is byte-identical to the first task of merge2 / item-sort-merged,
    # so those datasets' text assets apply here too; this is a re-collection of the
    # same task, not a new instruction.
    #
    # Steps: at batch_size 32 this set is 2092 step/epoch, so 20000 steps is ~9.6
    # epochs -- the lowest of the family, since it holds the most frames. Kept at
    # 20000 so all six G1 EEF runs cost the same and stay comparable step-for-step
    # (see pi05_g1_biomanual for the step-matched-not-epoch-matched rationale);
    # raise to ~65000 if you want epoch parity with the ~19k-frame tasks.
      name="pi05_g1_item_classification_new",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="item-classification-new-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
    # No separate eval split; None -> open-loop eval on the training dataset.
      eval_data_path = None,
    ),
    TrainConfig(
    # Unitree G1 Dex1 screwdriver-into-toolbox, EEF pose action space with 6D
    # rotation (same recipe as pi05_g1_biomanual / pi05_g1_drawer). Trains on
    # sort-tools-new-eef (100 eps / 32746 frames, episodes 241-435, mean 327).
    # Task: place the yellow screwdriver into the empty slot of the toolbox with
    # the left hand -- a fixed-arm single-phase task, unlike the "nearer arm"
    # phrasing the other G1 sets use.
    #
    # The prompt is byte-identical to the second task of hang-sort-merged /
    # item-sort-merged, so this is a re-collection of that task rather than a new
    # instruction.
    #
    # Steps: at batch_size 32 this set is 1023 step/epoch, so 20000 steps is ~19.5
    # epochs -- between drawer (~13) and the ~19k-frame tasks (~32-35). Kept at
    # 20000 for step parity with the rest of the family.
      name="pi05_g1_sort_tools_new",
      model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=48,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ),
      data=LeRobotUnitreeG1EEF6DDataConfig(
        repo_id="sort-tools-new-eef",
        base_config=DataConfig(
            local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            prompt_from_task=True,
        ),
      ),
      weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
      batch_size=32,
      num_workers=8,
      num_train_steps=20000,
      save_interval=4000,
      log_interval=100,
      keep_period=2000,
      wandb_enabled=True,
      lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=500,
        peak_lr=2.5e-5,
        decay_steps=15_000,
        decay_lr=2.5e-6,
      ),
      optimizer=_optimizer.AdamW(
        b1=0.9,
        b2=0.95,
        eps=1e-8,
        weight_decay=1e-4,
        clip_gradient_norm=1.0,
      ),
      freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m",
      ).get_freeze_filter(),
      ema_decay=0.99,
      eval_interval = 500,
      eval_episodes = 5,
      eval_stride= 20,
      eval_max_frames = None,
    # No separate eval split; None -> open-loop eval on the training dataset.
      eval_data_path = None,
    ),
    #
    # Fine-tuning Seeed B601 configs.
    #
    # Single-arm 7-dim pick-and-place, delivered as LeRobot v2.1 by the collection party. Only two
    # cameras, so b601_policy zero-fills and masks the right wrist view. The action expert is adapted
    # with LoRA while PaliGemma (vision + LLM) is fully fine-tuned; note that get_freeze_filter only
    # matches ".*llm.*", so the SigLIP tower stays trainable.
    #
    # Actions are absolute joint positions in degrees, and observation.state does NOT share the
    # action's coordinate convention: shoulder_pan, shoulder_lift, wrist_roll and gripper are
    # sign-flipped, and the gripper uses a different unit (state spans [-270, 0], action [0, 57]).
    # The state (follower) -> action (leader) conversion is NOT implemented here; a real-robot
    # client has to do it. State normalization is minmax, so a state outside the training range
    # saturates pi0.5's 256-bin state discretization.
    TrainConfig(
        name="pi05_b601_pick_red_cube",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=30,  # 30 fps -> ~1s action chunk
            action_expert_variant="gemma_300m_lora",
        ),
        data=LeRobotB601DataConfig(
            # Keep the slash: asset_id defaults to repo_id, and the delivered checkpoints bundle their
            # norm stats under assets/b601/pick_red_cube_v1/. Renaming this breaks checkpoint loading.
            repo_id="b601/pick_red_cube_v1",
            base_config=DataConfig(
                local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
                prompt_from_task=True,
                action_sequence_keys=("action",),
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=30,
            action_expert_variant="gemma_300m_lora",
        ).get_freeze_filter(),
        num_train_steps=30_000,
        batch_size=32,
        ema_decay=None,  # EMA is turned off for LoRA finetuning.
    ),
    # Same robot and data pipeline as above, but with the capacity split the other way round: LoRA on
    # the Gemma-2B LLM only, so its 2.5B of pretrained language weights stay frozen, while the action
    # expert -- the one part that has to learn B601's novel action space -- trains in full. The SigLIP
    # tower also trains in full; openpi has no mechanism to freeze or LoRA it (get_freeze_filter only
    # matches ".*llm.*"). This is the branch get_freeze_filter documents as "If only freeze gemma
    # params, exclude action expert params".
    #
    # Trainable 872.8M of 3.381B (25.8%): SigLIP 414.8M + action expert 427.9M + LLM LoRA 27.9M +
    # flow heads 2.2M. Frozen: the 2508.5M Gemma-2B base.
    #
    # Registered as a separate config rather than editing the one above because the two have different
    # parameter trees -- reusing the name would make the other's checkpoints unloadable. Norm stats are
    # shared via AssetsConfig so both configs read one file.
    TrainConfig(
        name="pi05_b601_pick_red_cube_llm_lora",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=30,  # 30 fps -> ~1s action chunk
            paligemma_variant="gemma_2b_lora",
            # action_expert_variant stays at the gemma_300m default: full fine-tuning.
        ),
        data=LeRobotB601DataConfig(
            repo_id="b601/pick_red_cube_v1",
            assets=AssetsConfig(
                assets_dir="./assets/pi05_b601_pick_red_cube",
                asset_id="b601/pick_red_cube_v1",
            ),
            base_config=DataConfig(
                local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
                prompt_from_task=True,
                action_sequence_keys=("action",),
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=30,
            paligemma_variant="gemma_2b_lora",
        ).get_freeze_filter(),
        num_train_steps=30_000,
        batch_size=32,
        # The default of 2 starves the GPUs: each sample decodes two AV1 streams, and splitting a
        # batch of 32 over four devices makes each step fast enough that the loader becomes the
        # bottleneck (observed ~30% idle time on all four GPUs).
        num_workers=8,
        # Kept at None so this run differs from pi05_b601_pick_red_cube in the capacity split alone.
        ema_decay=None,
    ),
    #
    # Fine-tuning RealMan RM65 configs.
    #
    # Right-arm 7-dim pick-and-hold over 4 objects (yellow Lay's, Nongfu Spring, hand soap, Coca-Cola),
    # 187 episodes / 66,121 frames, merged from the 4 per-task deliveries with scripts/merge_datasets.py.
    # The task string in tasks.jsonl names the object, so prompt_from_task selects the task.
    # Capacity split follows pi05_b601_pick_red_cube_llm_lora: SigLIP full + LLM LoRA + action expert full.
    #
    # Two configs differing only in the action representation; each keeps its own norm stats under
    # ./assets/<config name>/rm65/4tasks_v1/, because the delta variant's action stats are in delta space.
    TrainConfig(
        name="pi05_rm65_4tasks",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=30,  # 30 fps -> ~1s action chunk
            paligemma_variant="gemma_2b_lora",
        ),
        data=LeRobotRM65DataConfig(
            repo_id="rm65/4tasks_v1",
            base_config=DataConfig(
                local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
                prompt_from_task=True,
                action_sequence_keys=("action",),
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=30,
            paligemma_variant="gemma_2b_lora",
        ).get_freeze_filter(),
        num_train_steps=30_000,
        batch_size=32,
        num_workers=8,
        ema_decay=None,
    ),
    # Same as above, but the 6 joints are trained as deltas relative to the current state (gripper absolute).
    TrainConfig(
        name="pi05_rm65_4tasks_delta",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=30,
            paligemma_variant="gemma_2b_lora",
        ),
        data=LeRobotRM65DataConfig(
            repo_id="rm65/4tasks_v1",
            use_delta_joint_actions=True,
            base_config=DataConfig(
                local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
                prompt_from_task=True,
                action_sequence_keys=("action",),
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=30,
            paligemma_variant="gemma_2b_lora",
        ).get_freeze_filter(),
        num_train_steps=30_000,
        batch_size=32,
        num_workers=8,
        ema_decay=None,
    ),
    # Same as pi05_rm65_4tasks, but on rm65/4tasks_v1_trim (scripts/trim_static_frames.py): the static head
    # of every episode is dropped and the static tail is cut to 10 frames, 66,121 -> 58,399 frames.
    # Short mid-episode pauses are kept.
    TrainConfig(
        name="pi05_rm65_4tasks_trim",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=30,
            paligemma_variant="gemma_2b_lora",
        ),
        data=LeRobotRM65DataConfig(
            repo_id="rm65/4tasks_v1_trim",
            base_config=DataConfig(
                local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
                prompt_from_task=True,
                action_sequence_keys=("action",),
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=30,
            paligemma_variant="gemma_2b_lora",
        ).get_freeze_filter(),
        num_train_steps=30_000,
        batch_size=32,
        num_workers=8,
        ema_decay=None,
    ),
    # 2026-10-05 delivery: rightmost-object pick-and-hold over 4 new objects (yellow original / cucumber /
    # purple tomato chips, black Coca-Cola), 350 episodes. The 4 per-task lingbot_v033 folders were merged
    # with scripts/merge_datasets.py into rm65/4tasks_350_v2 and trimmed with scripts/trim_static_frames.py
    # (130,578 -> 123,698 frames). Training recipe copied from pi05_g1_eef: LLM LoRA + full action expert,
    # horizon 32, cosine LR 2.5e-5, EMA 0.99, 20k steps. Joint-space actions (absolute), as in pi05_rm65_4tasks.
    TrainConfig(
        name="pi05_rm65_4tasks_350",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=32,
            discrete_state_input=False,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m",
        ),
        data=LeRobotRM65DataConfig(
            repo_id="rm65/4tasks_350_v2_trim",
            base_config=DataConfig(
                local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
                prompt_from_task=True,
                action_sequence_keys=("action",),
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        batch_size=32,
        num_workers=8,
        num_train_steps=20000,
        save_interval=4000,
        log_interval=100,
        keep_period=2000,
        wandb_enabled=True,
        lr_schedule=_optimizer.CosineDecaySchedule(
            warmup_steps=500,
            peak_lr=2.5e-5,
            decay_steps=15_000,
            decay_lr=2.5e-6,
        ),
        optimizer=_optimizer.AdamW(
            b1=0.9,
            b2=0.95,
            eps=1e-8,
            weight_decay=1e-4,
            clip_gradient_norm=1.0,
        ),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m",
        ).get_freeze_filter(),
        ema_decay=0.99,
        eval_interval=500,
        eval_episodes=5,
        eval_stride=20,
        eval_max_frames=None,
        # No separate eval split; None -> eval on the training dataset.
        eval_data_path=None,
    ),


    TrainConfig(
     # This config is for fine-tuning pi05-base-mutitask on a custom multitask dataset.
     # Here, we use LeRobot data format (like for all other fine-tuning examples)
    name="pi05_ur3_multitask",
    model=pi0_config.Pi0Config(pi05=True, action_horizon=10, discrete_state_input=False, paligemma_variant="gemma_2b_lora", 
                                action_expert_variant="gemma_300m_lora",),
    data=LeRobotUR3MergedDataConfig(
        repo_id="zestcode5/ur3-multiple-task",
        base_config=DataConfig(
            prompt_from_task=True,
            # read from hub
            ),
        ),
#    weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
     weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),

    batch_size=96,
    num_train_steps=8000,
    save_interval=1000,
    log_interval=50,
    keep_period=2000,
    wandb_enabled=True,
    freeze_filter=pi0_config.Pi0Config(pi05=True,paligemma_variant="gemma_2b_lora",action_expert_variant="gemma_300m_lora",
    ).get_freeze_filter(),
    ema_decay=None,
    ),
    
    TrainConfig(
    #  for test not train
    # cp  ./assets/pi05_ur3_multitask → ./assets/pi0_5_multitask_old
    name="pi0_5_multitask_old",
    model=pi0_config.Pi0Config(
        pi05=True,
        action_horizon=10,
        discrete_state_input=False,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m_lora",
    ),
    data=OldLeRobotUR3MergedDataConfig(
        repo_id="zestcode5/ur3-multiple-task-trimmed-idle",
        base_config=DataConfig(
            prompt_from_task=True,
        ),
    ),
    weight_loader=weight_loaders.CheckpointWeightLoader(
        "gs://openpi-assets/checkpoints/pi05_base/params"
    ),
    # log from wandb
    batch_size=96,
    num_workers=2,
    num_train_steps=8000,
    save_interval=1000,
    log_interval=50,
    keep_period=2000,
    fsdp_devices=1,
    wandb_enabled=True,              
    lr_schedule=_optimizer.CosineDecaySchedule(
        warmup_steps=1_000,
        peak_lr=2.5e-5,
        decay_steps=30_000,
        decay_lr=2.5e-6,
    ),
    optimizer=_optimizer.AdamW(
        b1=0.9, b2=0.95, eps=1e-8,
        weight_decay=1e-10,
        clip_gradient_norm=1.0,
    ),
    freeze_filter=pi0_config.Pi0Config(
        pi05=True,
        paligemma_variant="gemma_2b_lora",
        action_expert_variant="gemma_300m_lora",
    ).get_freeze_filter(),
    ema_decay=None,
    ),
    
    
    TrainConfig(
        # T2 strategy: PaliGemma LoRA + Action Expert full fine-tuning.
        # Addresses the dual-LoRA capacity bottleneck (loss plateau at ~0.011
        # observed in pi05_ur3_multitask).
        # Dataset: UR3 multitask, ~612k frames. Hardware: 4x A100 80G with FSDP.
        name="pi05_ur3_multitask_full_action",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=10,
            discrete_state_input=False,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m",
        ),
        data=LeRobotUR3MergedDataConfig(
            repo_id="zestcode5/ur3-merged-3tasks-v1",
            base_config=DataConfig(
                prompt_from_task=True,
                # read from hub
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        
        batch_size=128,
        num_workers=16,
        num_train_steps=15000,
        save_interval=250,
        log_interval=10,
        keep_period=1000,
        fsdp_devices=4,
        wandb_enabled=True,
        lr_schedule=_optimizer.CosineDecaySchedule(
            warmup_steps=1_000,
            peak_lr=2.5e-5,
            decay_steps=30_000,
            decay_lr=2.5e-6,
        ),
        optimizer=_optimizer.AdamW(
            b1=0.9,
            b2=0.95,
            eps=1e-8,
            weight_decay=1e-4,
            clip_gradient_norm=1.0,
        ),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m",
        ).get_freeze_filter(),
        ema_decay=0.99,
    ),
    
    TrainConfig(
        # T2 strategy: PaliGemma LoRA + Action Expert full fine-tuning.
        # Addresses the dual-LoRA capacity bottleneck (loss plateau at ~0.011
        # observed in pi05_ur3_multitask).
        # Dataset: UR3 multitask, ~612k frames. Hardware: 4x A100 80G with FSDP.
        name="pi05_ur3_multitask_test_full_action",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=10,
            discrete_state_input=False,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m",
        ),
        data=LeRobotUR3MergedDataConfig(
            repo_id="zestcode5/ur3-multiple-task-trimmed-idle",
            base_config=DataConfig(
                prompt_from_task=True,
                # read from hub
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        
        batch_size=128,
        num_workers=16,
        num_train_steps=15000,
        save_interval=250,
        log_interval=10,
        keep_period=1000,
        fsdp_devices=4,
        wandb_enabled=True,
        lr_schedule=_optimizer.CosineDecaySchedule(
            warmup_steps=1_000,
            peak_lr=2.5e-5,
            decay_steps=30_000,
            decay_lr=2.5e-6,
        ),
        optimizer=_optimizer.AdamW(
            b1=0.9,
            b2=0.95,
            eps=1e-8,
            weight_decay=1e-4,
            clip_gradient_norm=1.0,
        ),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m",
        ).get_freeze_filter(),
        ema_decay=0.99,
    ),
    TrainConfig(
        # T2 strategy: PaliGemma LoRA + Action Expert full fine-tuning.
        # Addresses the dual-LoRA capacity bottleneck (loss plateau at ~0.011
        # observed in pi05_ur3_multitask).
        # Dataset: UR3 multitask, ~612k frames. Hardware: 4x A100 80G with FSDP.
        name="pi05_ur3_5task",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=10,
            discrete_state_input=False,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m",
        ),
        data=LeRobotUR3MergedDataConfig(
            repo_id="zestcode5/ur3-merged-5tasks-v1",
            base_config=DataConfig(
                prompt_from_task=True,
                # read from hub
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        
        batch_size=128,
        num_workers=16,
        num_train_steps=15000,
        save_interval=250,
        log_interval=10,
        keep_period=1000,
        fsdp_devices=4,
        wandb_enabled=True,
        lr_schedule=_optimizer.CosineDecaySchedule(
            warmup_steps=1_000,
            peak_lr=2.5e-5,
            decay_steps=30_000,
            decay_lr=2.5e-6,
        ),
        optimizer=_optimizer.AdamW(
            b1=0.9,
            b2=0.95,
            eps=1e-8,
            weight_decay=1e-4,
            clip_gradient_norm=1.0,
        ),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m",
        ).get_freeze_filter(),
        ema_decay=0.99,
    ),
    
    
        TrainConfig(
        # T2 strategy: PaliGemma LoRA + Action Expert full fine-tuning.
        # Addresses the dual-LoRA capacity bottleneck (loss plateau at ~0.011
        # observed in pi05_ur3_multitask).
        # Dataset: UR3 multitask, ~612k frames. Hardware: 4x A100 80G with FSDP.
        name="pi05_ur3_4task",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=10,
            discrete_state_input=False,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m",
        ),
        data=LeRobotUR3MergedDataConfig(
            repo_id="zestcode5/ur3-merged-4tasks-v1",
            base_config=DataConfig(
                prompt_from_task=True,
                # read from hub
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        
        batch_size=128,
        num_workers=16,
        num_train_steps=15000,
        save_interval=250,
        log_interval=10,
        keep_period=1000,
        fsdp_devices=4,
        wandb_enabled=True,
        lr_schedule=_optimizer.CosineDecaySchedule(
            warmup_steps=1_000,
            peak_lr=2.5e-5,
            decay_steps=30_000,
            decay_lr=2.5e-6,
        ),
        optimizer=_optimizer.AdamW(
            b1=0.9,
            b2=0.95,
            eps=1e-8,
            weight_decay=1e-4,
            clip_gradient_norm=1.0,
        ),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m",
        ).get_freeze_filter(),
        ema_decay=0.99,
    ),
    
    TrainConfig(
     # This config is for fine-tuning pi05-base-mutitask on a custom multitask dataset.
     # Here, we use LeRobot data format (like for all other fine-tuning examples)
    name="pi05_ur3_push_glass",
    model=pi0_config.Pi0Config(pi05=True, action_horizon=10, discrete_state_input=False, paligemma_variant="gemma_2b_lora", 
                                action_expert_variant="gemma_300m_lora",),
    data=LeRobotUR3MergedDataConfig(
        repo_id="poweredshine/ur3-single-finger-pushing-glass-to-marker",
        base_config=DataConfig(
            prompt_from_task=True,
            # read from hub
            ),
        ),
#    weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
     weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),

    batch_size=96,
    num_train_steps=8000,
    save_interval=1000,
    log_interval=50,
    keep_period=2000,
    wandb_enabled=True,
    freeze_filter=pi0_config.Pi0Config(pi05=True,paligemma_variant="gemma_2b_lora",action_expert_variant="gemma_300m_lora",
    ).get_freeze_filter(),
    ema_decay=None,
    ),
    
    
    TrainConfig(
        # Dual-arm UR3 (LGG100/ur3-test cleaned: 22 eps / 3620 frames @ 15 Hz, 14-dim joints, 3 cameras),
        # see scripts/clean_ur3_bimanual_lerobot.py.
        # PaliGemma LoRA + Action Expert LoRA, following pi05_ur3_multitask / pi05_ur3_push_glass.
        name="pi05_ur3_bimanual_lora",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=10,
            discrete_state_input=False,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m_lora",
        ),
        data=LeRobotUR3BimanualDataConfig(
            repo_id="ur3-test-clean",
            base_config=DataConfig(
                local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
                prompt_from_task=True,
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        batch_size=32,
        num_workers=8,
        num_train_steps=10000,
        save_interval=1000,
        log_interval=50,
        keep_period=2000,
        wandb_enabled=True,
        lr_schedule=_optimizer.CosineDecaySchedule(
            warmup_steps=500,
            peak_lr=2.5e-5,
            decay_steps=10_000,
            decay_lr=2.5e-6,
        ),
        optimizer=_optimizer.AdamW(
            b1=0.9,
            b2=0.95,
            eps=1e-8,
            weight_decay=1e-4,
            clip_gradient_norm=1.0,
        ),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=10,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m_lora",
        ).get_freeze_filter(),
        ema_decay=None,
    ),

    TrainConfig(
        # Bimanual UR3 (ur3-test-clean), config/policy from https://huggingface.co/LGG100/ur3-test-lora
        # (pi05_ur3_test_lora: aloha_policy with adapt_to_pi=False), action_horizon 10 -> 32.
        # LoRA on both PaliGemma and the action expert, single GPU.
        name="pi05_ur3_test_lora_h32",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=32,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m_lora",
        ),
        data=LeRobotAlohaDataConfig(
            repo_id="ur3-test-clean",
            base_config=DataConfig(
                prompt_from_task=True,
                local_root=pathlib.Path("/shared/user64/workspace/yuhao/pi/data"),
            ),
            adapt_to_pi=False,
            repack_transforms=_transforms.Group(
                inputs=[
                    _transforms.RepackTransform(
                        {
                            "images": {
                                "cam_high": "observation.images.cam_high",
                                "cam_left_wrist": "observation.images.cam_left_wrist",
                                "cam_right_wrist": "observation.images.cam_right_wrist",
                            },
                            "state": "observation.state",
                            "actions": "action",
                            "prompt": "prompt",
                        }
                    )
                ]
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        batch_size=32,
        num_workers=8,
        num_train_steps=4000,
        save_interval=1000,
        keep_period=1000,
        log_interval=50,
        lr_schedule=_optimizer.CosineDecaySchedule(
            warmup_steps=200,
            peak_lr=2.5e-5,
            decay_steps=4000,
            decay_lr=2.5e-6,
        ),
        freeze_filter=pi0_config.Pi0Config(
            pi05=True,
            action_horizon=32,
            paligemma_variant="gemma_2b_lora",
            action_expert_variant="gemma_300m_lora",
        ).get_freeze_filter(),
        ema_decay=None,
    ),

    TrainConfig(
        name="pi0_aloha",
        model=pi0_config.Pi0Config(),
        data=LeRobotAlohaDataConfig(
            assets=AssetsConfig(asset_id="trossen"),
        ),
        policy_metadata={"reset_pose": [0, -1.5, 1.5, 0, 0, 0]},
    ),
    TrainConfig(
        name="pi05_aloha",
        model=pi0_config.Pi0Config(pi05=True),
        data=LeRobotAlohaDataConfig(
            assets=AssetsConfig(asset_id="trossen"),
        ),
        policy_metadata={"reset_pose": [0, -1.5, 1.5, 0, 0, 0]},
    ),
    TrainConfig(
        name="pi0_aloha_towel",
        model=pi0_config.Pi0Config(),
        data=LeRobotAlohaDataConfig(
            assets=AssetsConfig(asset_id="trossen"),
            default_prompt="fold the towel",
        ),
        policy_metadata={"reset_pose": [0, -1.5, 1.5, 0, 0, 0]},
    ),
    TrainConfig(
        name="pi0_aloha_tupperware",
        model=pi0_config.Pi0Config(),
        data=LeRobotAlohaDataConfig(
            assets=AssetsConfig(asset_id="trossen"),
            default_prompt="open the tupperware and put the food on the plate",
        ),
        policy_metadata={"reset_pose": [0, -1.5, 1.5, 0, 0, 0]},
    ),
    #
    # Inference DROID configs.
    #
    TrainConfig(
        name="pi0_droid",
        model=pi0_config.Pi0Config(action_horizon=10),
        data=SimpleDataConfig(
            assets=AssetsConfig(asset_id="droid"),
            data_transforms=lambda model: _transforms.Group(
                inputs=[droid_policy.DroidInputs(model_type=ModelType.PI0)],
                outputs=[droid_policy.DroidOutputs()],
            ),
            base_config=DataConfig(
                prompt_from_task=True,
            ),
        ),
    ),
    TrainConfig(
        name="pi0_fast_droid",
        model=pi0_fast.Pi0FASTConfig(action_dim=8, action_horizon=10),
        data=SimpleDataConfig(
            assets=AssetsConfig(asset_id="droid"),
            data_transforms=lambda model: _transforms.Group(
                inputs=[droid_policy.DroidInputs(model_type=ModelType.PI0_FAST)],
                outputs=[droid_policy.DroidOutputs()],
            ),
            base_config=DataConfig(
                prompt_from_task=True,
            ),
        ),
    ),
    TrainConfig(
        name="pi05_droid",
        model=pi0_config.Pi0Config(action_horizon=15, pi05=True),
        data=SimpleDataConfig(
            assets=AssetsConfig(asset_id="droid"),
            data_transforms=lambda model: _transforms.Group(
                inputs=[droid_policy.DroidInputs(model_type=ModelType.PI05)],
                outputs=[droid_policy.DroidOutputs()],
            ),
            base_config=DataConfig(
                prompt_from_task=True,
            ),
        ),
    ),
    #
    # Fine-tuning Libero configs.
    #
    # These train configs define the hyperparameters for fine-tuning the base model on your own dataset.
    # They are used to define key elements like the dataset you are training on, the base checkpoint you
    # are using, and other hyperparameters like how many training steps to run or what learning rate to use.
    # For your own dataset, you can copy this class and modify the dataset name, and data transforms based on
    # the comments below.
    TrainConfig(
        # Change the name to reflect your model and dataset.
        name="pi0_libero",
        # Here you define the model config -- In this example we use pi0 as the model
        # architecture and perform *full* finetuning. in the examples below we show how to modify
        # this to perform *low-memory* (LORA) finetuning and use pi0-FAST as an alternative architecture.
        model=pi0_config.Pi0Config(),
        # Here you define the dataset you are training on. In this example we use the Libero
        # dataset. For your own dataset, you can change the repo_id to point to your dataset.
        # Also modify the DataConfig to use the new config you made for your dataset above.
        data=LeRobotLiberoDataConfig(
            repo_id="physical-intelligence/libero",
            base_config=DataConfig(
                # This flag determines whether we load the prompt (i.e. the task instruction) from the
                # ``task`` field in the LeRobot dataset. If set to True, the prompt will show up in
                # a field called ``prompt`` in the input dict. The recommended setting is True.
                prompt_from_task=True,
            ),
            extra_delta_transform=True,
        ),
        # Here you define which pre-trained checkpoint you want to load to initialize the model.
        # This should match the model config you chose above -- i.e. in this case we use the pi0 base model.
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi0_base/params"),
        # Below you can define other hyperparameters like the learning rate, number of training steps, etc.
        # Check the base TrainConfig class for a full list of available hyperparameters.
        num_train_steps=30_000,
    ),
    TrainConfig(
        name="pi0_libero_low_mem_finetune",
        # Here is an example of loading a pi0 model for LoRA fine-tuning.
        model=pi0_config.Pi0Config(paligemma_variant="gemma_2b_lora", action_expert_variant="gemma_300m_lora"),
        data=LeRobotLiberoDataConfig(
            repo_id="physical-intelligence/libero",
            base_config=DataConfig(prompt_from_task=True),
            extra_delta_transform=True,
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi0_base/params"),
        num_train_steps=30_000,
        # The freeze filter defines which parameters should be frozen during training.
        # We have a convenience function in the model config that returns the default freeze filter
        # for the given model config for LoRA finetuning. Just make sure it matches the model config
        # you chose above.
        freeze_filter=pi0_config.Pi0Config(
            paligemma_variant="gemma_2b_lora", action_expert_variant="gemma_300m_lora"
        ).get_freeze_filter(),
        # Turn off EMA for LoRA finetuning.
        ema_decay=None,
    ),
    TrainConfig(
        name="pi0_fast_libero",
        # Here is an example of loading a pi0-FAST model for full finetuning.
        # Modify action_dim and action_horizon to match your dataset (action horizon is equal to
        # the desired action chunk length).
        # The max_token_len is the maximum number of (non-image) tokens the model can handle.
        # This includes the tokenized prompt, proprioceptive state, and (FAST-tokenized) action tokens.
        # Choosing this value too small may chop off tokens at the end of your sequence (the code will throw
        # a warning), while choosing it too large will waste memory (since we pad each batch element to the
        # max_token_len). A good rule of thumb is to use approx 180 for single-arm robots, and approx 250 for
        # two-arm robots. Generally, err on the lower side here first, and potentially increase the value if
        # you see many warnings being thrown during training.
        model=pi0_fast.Pi0FASTConfig(action_dim=7, action_horizon=10, max_token_len=180),
        data=LeRobotLiberoDataConfig(
            repo_id="physical-intelligence/libero",
            base_config=DataConfig(prompt_from_task=True),
            extra_delta_transform=True,
        ),
        # Note that we load the pi0-FAST base model checkpoint here.
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi0_fast_base/params"),
        num_train_steps=30_000,
    ),
    TrainConfig(
        name="pi0_fast_libero_low_mem_finetune",
        # Here is an example of loading a pi0-FAST model for LoRA finetuning.
        # For setting action_dim, action_horizon, and max_token_len, see the comments above.
        model=pi0_fast.Pi0FASTConfig(
            action_dim=7, action_horizon=10, max_token_len=180, paligemma_variant="gemma_2b_lora"
        ),
        data=LeRobotLiberoDataConfig(
            repo_id="physical-intelligence/libero",
            base_config=DataConfig(prompt_from_task=True),
            extra_delta_transform=True,
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi0_fast_base/params"),
        num_train_steps=30_000,
        # Again, make sure to match the model config above when extracting the freeze filter
        # that specifies which parameters should be frozen during LoRA finetuning.
        freeze_filter=pi0_fast.Pi0FASTConfig(
            action_dim=7, action_horizon=10, max_token_len=180, paligemma_variant="gemma_2b_lora"
        ).get_freeze_filter(),
        # Turn off EMA for LoRA finetuning.
        ema_decay=None,
    ),
    TrainConfig(
        name="pi05_libero",
        model=pi0_config.Pi0Config(pi05=True, action_horizon=10, discrete_state_input=False),
        data=LeRobotLiberoDataConfig(
            repo_id="physical-intelligence/libero",
            base_config=DataConfig(prompt_from_task=True),
            extra_delta_transform=False,
        ),
        batch_size=256,
        lr_schedule=_optimizer.CosineDecaySchedule(
            warmup_steps=10_000,
            peak_lr=5e-5,
            decay_steps=1_000_000,
            decay_lr=5e-5,
        ),
        optimizer=_optimizer.AdamW(clip_gradient_norm=1.0),
        ema_decay=0.999,
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        pytorch_weight_path="/path/to/your/pytorch_weight_path",
        num_train_steps=30_000,
    ),
    #
    # Fine-tuning Aloha configs.
    #
    # This is a test config that is used to illustate how train on a custom LeRobot dataset.
    # For instructions on how to convert and train on your own Aloha dataset see examples/aloha_real/README.md
    TrainConfig(
        name="pi0_aloha_pen_uncap",
        model=pi0_config.Pi0Config(),
        data=LeRobotAlohaDataConfig(
            repo_id="physical-intelligence/aloha_pen_uncap_diverse",
            assets=AssetsConfig(
                assets_dir="gs://openpi-assets/checkpoints/pi0_base/assets",
                asset_id="trossen",
            ),
            default_prompt="uncap the pen",
            repack_transforms=_transforms.Group(
                inputs=[
                    _transforms.RepackTransform(
                        {
                            "images": {
                                "cam_high": "observation.images.cam_high",
                                "cam_left_wrist": "observation.images.cam_left_wrist",
                                "cam_right_wrist": "observation.images.cam_right_wrist",
                            },
                            "state": "observation.state",
                            "actions": "action",
                        }
                    )
                ]
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi0_base/params"),
        num_train_steps=20_000,
    ),
    TrainConfig(
        name="pi05_aloha_pen_uncap",
        model=pi0_config.Pi0Config(pi05=True),
        data=LeRobotAlohaDataConfig(
            repo_id="physical-intelligence/aloha_pen_uncap_diverse",
            assets=AssetsConfig(
                assets_dir="gs://openpi-assets/checkpoints/pi05_base/assets",
                asset_id="trossen",
            ),
            default_prompt="uncap the pen",
            repack_transforms=_transforms.Group(
                inputs=[
                    _transforms.RepackTransform(
                        {
                            "images": {
                                "cam_high": "observation.images.cam_high",
                                "cam_left_wrist": "observation.images.cam_left_wrist",
                                "cam_right_wrist": "observation.images.cam_right_wrist",
                            },
                            "state": "observation.state",
                            "actions": "action",
                        }
                    )
                ]
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        num_train_steps=20_000,
        batch_size=64,
    ),
    #
    # Fine-tuning DROID configs.
    #
    TrainConfig(
        # This config is for fine-tuning pi0-FAST-base on the *full* DROID dataset.
        # We use RLDS data loading to make training on this large dataset tractable.
        # For fine-tuning on your own DROID dataset, see below.
        name="pi0_fast_full_droid_finetune",
        model=pi0_fast.Pi0FASTConfig(
            action_dim=8,
            action_horizon=16,
            max_token_len=180,
        ),
        data=RLDSDroidDataConfig(
            repo_id="droid",
            # Set this to the path to your DROID RLDS dataset (the parent directory of the `droid` directory).
            rlds_data_dir="<path_to_droid_rlds_dataset>",
            action_space=droid_rlds_dataset.DroidActionSpace.JOINT_POSITION,
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi0_fast_base/params"),
        lr_schedule=_optimizer.CosineDecaySchedule(
            warmup_steps=1_000,
            peak_lr=5e-5,
            decay_steps=1_000_000,
            decay_lr=5e-5,
        ),
        num_train_steps=100_000,  # 100k steps should be sufficient, takes ~2 days on 8x H100s
        batch_size=256,
        log_interval=100,
        save_interval=5000,
        keep_period=20_000,
        num_workers=0,  # Important: RLDS DataLoader requires num_workers=0, handles multi-processing internally
    ),
    TrainConfig(
        # This config is for fine-tuning pi05 on the *full* DROID dataset.
        # We use RLDS data loading to make training on this large dataset tractable.
        # For fine-tuning on your own DROID dataset, see below.
        name="pi05_full_droid_finetune",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_dim=32,
            action_horizon=16,
        ),
        data=RLDSDroidDataConfig(
            repo_id="droid",
            # Set this to the path to your DROID RLDS dataset (the parent directory of the `droid` directory).
            rlds_data_dir="/mnt/pi-data/kevin",
            action_space=droid_rlds_dataset.DroidActionSpace.JOINT_POSITION,
            assets=AssetsConfig(
                assets_dir="gs://openpi-assets/checkpoints/pi05_base/assets/",
                asset_id="droid",
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_base/params"),
        lr_schedule=_optimizer.CosineDecaySchedule(
            warmup_steps=1_000,
            peak_lr=5e-5,
            decay_steps=1_000_000,
            decay_lr=5e-5,
        ),
        num_train_steps=100_000,
        batch_size=256,
        log_interval=100,
        save_interval=5000,
        keep_period=10_000,
        num_workers=0,  # Important: RLDS DataLoader requires num_workers=0, handles multi-processing internally
    ),
    TrainConfig(
        # This config is for fine-tuning pi05-DROID on a custom (smaller) DROID dataset.
        # Here, we use LeRobot data format (like for all other fine-tuning examples)
        # To convert your custom DROID dataset (<10s of hours) to LeRobot format, see examples/droid/convert_droid_data_to_lerobot.py
        name="pi05_droid_finetune",
        model=pi0_config.Pi0Config(
            pi05=True,
            action_dim=32,  # pi05 is trained with 32-dim actions
            action_horizon=16,
        ),
        data=LeRobotDROIDDataConfig(
            # Replace with your custom DROID LeRobot dataset repo id.
            repo_id="your_hf_username/my_droid_dataset",
            base_config=DataConfig(prompt_from_task=True),
            assets=AssetsConfig(
                # Important: reuse the original DROID norm stats during fine-tuning!
                assets_dir="gs://openpi-assets/checkpoints/pi05_droid/assets",
                asset_id="droid",
            ),
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi05_droid/params"),
        num_train_steps=20_000,
        batch_size=32,
    ),
    
    
    #
    # ALOHA Sim configs. This config is used to demonstrate how to train on a simple simulated environment.
    #
    TrainConfig(
        name="pi0_aloha_sim",
        model=pi0_config.Pi0Config(),
        data=LeRobotAlohaDataConfig(
            repo_id="lerobot/aloha_sim_transfer_cube_human",
            default_prompt="Transfer cube",
            use_delta_joint_actions=False,
        ),
        weight_loader=weight_loaders.CheckpointWeightLoader("gs://openpi-assets/checkpoints/pi0_base/params"),
        num_train_steps=20_000,
    ),
    #
    # Debugging configs.
    #
    TrainConfig(
        name="debug",
        data=FakeDataConfig(),
        batch_size=2,
        model=pi0_config.Pi0Config(paligemma_variant="dummy", action_expert_variant="dummy"),
        save_interval=100,
        overwrite=True,
        exp_name="debug",
        num_train_steps=10,
        wandb_enabled=False,
    ),
    TrainConfig(
        name="debug_restore",
        data=FakeDataConfig(),
        batch_size=2,
        model=pi0_config.Pi0Config(paligemma_variant="dummy", action_expert_variant="dummy"),
        weight_loader=weight_loaders.CheckpointWeightLoader("./checkpoints/debug/debug/9/params"),
        overwrite=True,
        exp_name="debug",
        num_train_steps=10,
        wandb_enabled=False,
    ),
    TrainConfig(
        name="debug_pi05",
        model=pi0_config.Pi0Config(pi05=True, paligemma_variant="dummy", action_expert_variant="dummy"),
        data=FakeDataConfig(),
        batch_size=2,
        num_train_steps=10,
        overwrite=True,
        exp_name="debug_pi05",
        wandb_enabled=False,
    ),
    # RoboArena & PolaRiS configs.
    *roboarena_config.get_roboarena_configs(),
    *polaris_config.get_polaris_configs(),
]

if len({config.name for config in _CONFIGS}) != len(_CONFIGS):
    raise ValueError("Config names must be unique.")
_CONFIGS_DICT = {config.name: config for config in _CONFIGS}


def cli() -> TrainConfig:
    return tyro.extras.overridable_config_cli({k: (k, v) for k, v in _CONFIGS_DICT.items()})


def get_config(config_name: str) -> TrainConfig:
    """Get a config by name."""
    if config_name not in _CONFIGS_DICT:
        closest = difflib.get_close_matches(config_name, _CONFIGS_DICT.keys(), n=1, cutoff=0.0)
        closest_str = f" Did you mean '{closest[0]}'? " if closest else ""
        raise ValueError(f"Config '{config_name}' not found.{closest_str}")

    return _CONFIGS_DICT[config_name]