-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinetuning.go
More file actions
3248 lines (2930 loc) · 137 KB
/
finetuning.go
File metadata and controls
3248 lines (2930 loc) · 137 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package together
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/togethercomputer/together-go/internal/apijson"
"github.com/togethercomputer/together-go/internal/apiquery"
"github.com/togethercomputer/together-go/internal/requestconfig"
"github.com/togethercomputer/together-go/option"
"github.com/togethercomputer/together-go/packages/param"
"github.com/togethercomputer/together-go/packages/respjson"
"github.com/togethercomputer/together-go/shared/constant"
)
// FineTuningService contains methods and other services that help with interacting
// with the together API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewFineTuningService] method instead.
type FineTuningService struct {
Options []option.RequestOption
}
// NewFineTuningService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewFineTuningService(opts ...option.RequestOption) (r FineTuningService) {
r = FineTuningService{}
r.Options = opts
return
}
// Create a fine-tuning job with the provided model and training data.
func (r *FineTuningService) New(ctx context.Context, body FineTuningNewParams, opts ...option.RequestOption) (res *FineTuningNewResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "fine-tunes"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// List the metadata for a single fine-tuning job.
func (r *FineTuningService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *FinetuneResponse, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("fine-tunes/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// List the metadata for all fine-tuning jobs. Returns a list of
// FinetuneResponseTruncated objects.
func (r *FineTuningService) List(ctx context.Context, opts ...option.RequestOption) (res *FineTuningListResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "fine-tunes"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// Delete a fine-tuning job.
func (r *FineTuningService) Delete(ctx context.Context, id string, body FineTuningDeleteParams, opts ...option.RequestOption) (res *FineTuningDeleteResponse, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("fine-tunes/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, body, &res, opts...)
return res, err
}
// Cancel a currently running fine-tuning job. Returns a FinetuneResponseTruncated
// object.
func (r *FineTuningService) Cancel(ctx context.Context, id string, opts ...option.RequestOption) (res *FineTuningCancelResponse, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("fine-tunes/%s/cancel", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return res, err
}
// Receive a compressed fine-tuned model or checkpoint.
func (r *FineTuningService) Content(ctx context.Context, query FineTuningContentParams, opts ...option.RequestOption) (res *http.Response, err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "application/octet-stream")}, opts...)
path := "finetune/download"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// Estimate the price of a fine-tuning job.
func (r *FineTuningService) EstimatePrice(ctx context.Context, body FineTuningEstimatePriceParams, opts ...option.RequestOption) (res *FineTuningEstimatePriceResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "fine-tunes/estimate-price"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// List the checkpoints for a single fine-tuning job.
func (r *FineTuningService) ListCheckpoints(ctx context.Context, id string, opts ...option.RequestOption) (res *FineTuningListCheckpointsResponse, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("fine-tunes/%s/checkpoints", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// List the events for a single fine-tuning job.
func (r *FineTuningService) ListEvents(ctx context.Context, id string, opts ...option.RequestOption) (res *FineTuningListEventsResponse, err error) {
opts = slices.Concat(r.Options, opts)
if id == "" {
err = errors.New("missing required id parameter")
return nil, err
}
path := fmt.Sprintf("fine-tunes/%s/events", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
type FinetuneEvent struct {
CheckpointPath string `json:"checkpoint_path" api:"required"`
CreatedAt string `json:"created_at" api:"required"`
Hash string `json:"hash" api:"required"`
Message string `json:"message" api:"required"`
ModelPath string `json:"model_path" api:"required"`
// The object type, which is always `fine-tune-event`.
Object constant.FineTuneEvent `json:"object" default:"fine-tune-event"`
ParamCount int64 `json:"param_count" api:"required"`
Step int64 `json:"step" api:"required"`
TokenCount int64 `json:"token_count" api:"required"`
TotalSteps int64 `json:"total_steps" api:"required"`
TrainingOffset int64 `json:"training_offset" api:"required"`
// Any of "job_pending", "job_start", "job_stopped", "model_downloading",
// "model_download_complete", "training_data_downloading",
// "training_data_download_complete", "validation_data_downloading",
// "validation_data_download_complete", "wandb_init", "training_start",
// "checkpoint_save", "billing_limit", "epoch_complete", "training_complete",
// "model_compressing", "model_compression_complete", "model_uploading",
// "model_upload_complete", "job_complete", "job_error", "cancel_requested",
// "job_restarted", "refund", "warning".
Type FinetuneEventType `json:"type" api:"required"`
WandbURL string `json:"wandb_url" api:"required"`
// Any of "info", "warning", "error", "legacy_info", "legacy_iwarning",
// "legacy_ierror".
Level FinetuneEventLevel `json:"level" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CheckpointPath respjson.Field
CreatedAt respjson.Field
Hash respjson.Field
Message respjson.Field
ModelPath respjson.Field
Object respjson.Field
ParamCount respjson.Field
Step respjson.Field
TokenCount respjson.Field
TotalSteps respjson.Field
TrainingOffset respjson.Field
Type respjson.Field
WandbURL respjson.Field
Level respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneEvent) RawJSON() string { return r.JSON.raw }
func (r *FinetuneEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneEventLevel string
const (
FinetuneEventLevelInfo FinetuneEventLevel = "info"
FinetuneEventLevelWarning FinetuneEventLevel = "warning"
FinetuneEventLevelError FinetuneEventLevel = "error"
FinetuneEventLevelLegacyInfo FinetuneEventLevel = "legacy_info"
FinetuneEventLevelLegacyIwarning FinetuneEventLevel = "legacy_iwarning"
FinetuneEventLevelLegacyIerror FinetuneEventLevel = "legacy_ierror"
)
type FinetuneEventType string
const (
FinetuneEventTypeJobPending FinetuneEventType = "job_pending"
FinetuneEventTypeJobStart FinetuneEventType = "job_start"
FinetuneEventTypeJobStopped FinetuneEventType = "job_stopped"
FinetuneEventTypeModelDownloading FinetuneEventType = "model_downloading"
FinetuneEventTypeModelDownloadComplete FinetuneEventType = "model_download_complete"
FinetuneEventTypeTrainingDataDownloading FinetuneEventType = "training_data_downloading"
FinetuneEventTypeTrainingDataDownloadComplete FinetuneEventType = "training_data_download_complete"
FinetuneEventTypeValidationDataDownloading FinetuneEventType = "validation_data_downloading"
FinetuneEventTypeValidationDataDownloadComplete FinetuneEventType = "validation_data_download_complete"
FinetuneEventTypeWandbInit FinetuneEventType = "wandb_init"
FinetuneEventTypeTrainingStart FinetuneEventType = "training_start"
FinetuneEventTypeCheckpointSave FinetuneEventType = "checkpoint_save"
FinetuneEventTypeBillingLimit FinetuneEventType = "billing_limit"
FinetuneEventTypeEpochComplete FinetuneEventType = "epoch_complete"
FinetuneEventTypeTrainingComplete FinetuneEventType = "training_complete"
FinetuneEventTypeModelCompressing FinetuneEventType = "model_compressing"
FinetuneEventTypeModelCompressionComplete FinetuneEventType = "model_compression_complete"
FinetuneEventTypeModelUploading FinetuneEventType = "model_uploading"
FinetuneEventTypeModelUploadComplete FinetuneEventType = "model_upload_complete"
FinetuneEventTypeJobComplete FinetuneEventType = "job_complete"
FinetuneEventTypeJobError FinetuneEventType = "job_error"
FinetuneEventTypeCancelRequested FinetuneEventType = "cancel_requested"
FinetuneEventTypeJobRestarted FinetuneEventType = "job_restarted"
FinetuneEventTypeRefund FinetuneEventType = "refund"
FinetuneEventTypeWarning FinetuneEventType = "warning"
)
type FinetuneResponse struct {
ID string `json:"id" api:"required" format:"uuid"`
// Any of "pending", "queued", "running", "compressing", "uploading",
// "cancel_requested", "cancelled", "error", "completed".
Status FinetuneResponseStatus `json:"status" api:"required"`
BatchSize FinetuneResponseBatchSizeUnion `json:"batch_size"`
CreatedAt time.Time `json:"created_at" format:"date-time"`
EpochsCompleted int64 `json:"epochs_completed"`
EvalSteps int64 `json:"eval_steps"`
Events []FinetuneEvent `json:"events"`
FromCheckpoint string `json:"from_checkpoint"`
FromHfModel string `json:"from_hf_model"`
HfModelRevision string `json:"hf_model_revision"`
JobID string `json:"job_id"`
LearningRate float64 `json:"learning_rate"`
LrScheduler FinetuneResponseLrScheduler `json:"lr_scheduler"`
MaxGradNorm float64 `json:"max_grad_norm"`
Model string `json:"model"`
ModelOutputName string `json:"model_output_name"`
ModelOutputPath string `json:"model_output_path"`
MultimodalParams FinetuneResponseMultimodalParams `json:"multimodal_params"`
NCheckpoints int64 `json:"n_checkpoints"`
NEpochs int64 `json:"n_epochs"`
NEvals int64 `json:"n_evals"`
ParamCount int64 `json:"param_count"`
// Progress information for a fine-tuning job
Progress FinetuneResponseProgress `json:"progress"`
QueueDepth int64 `json:"queue_depth"`
StartedAt time.Time `json:"started_at" format:"date-time"`
TokenCount int64 `json:"token_count"`
TotalPrice int64 `json:"total_price"`
TrainOnInputs FinetuneResponseTrainOnInputsUnion `json:"train_on_inputs"`
TrainingFile string `json:"training_file"`
TrainingMethod FinetuneResponseTrainingMethodUnion `json:"training_method"`
TrainingType FinetuneResponseTrainingTypeUnion `json:"training_type"`
TrainingfileNumlines int64 `json:"trainingfile_numlines"`
TrainingfileSize int64 `json:"trainingfile_size"`
UpdatedAt time.Time `json:"updated_at" format:"date-time"`
ValidationFile string `json:"validation_file"`
WandbProjectName string `json:"wandb_project_name"`
WandbURL string `json:"wandb_url"`
WarmupRatio float64 `json:"warmup_ratio"`
WeightDecay float64 `json:"weight_decay"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Status respjson.Field
BatchSize respjson.Field
CreatedAt respjson.Field
EpochsCompleted respjson.Field
EvalSteps respjson.Field
Events respjson.Field
FromCheckpoint respjson.Field
FromHfModel respjson.Field
HfModelRevision respjson.Field
JobID respjson.Field
LearningRate respjson.Field
LrScheduler respjson.Field
MaxGradNorm respjson.Field
Model respjson.Field
ModelOutputName respjson.Field
ModelOutputPath respjson.Field
MultimodalParams respjson.Field
NCheckpoints respjson.Field
NEpochs respjson.Field
NEvals respjson.Field
ParamCount respjson.Field
Progress respjson.Field
QueueDepth respjson.Field
StartedAt respjson.Field
TokenCount respjson.Field
TotalPrice respjson.Field
TrainOnInputs respjson.Field
TrainingFile respjson.Field
TrainingMethod respjson.Field
TrainingType respjson.Field
TrainingfileNumlines respjson.Field
TrainingfileSize respjson.Field
UpdatedAt respjson.Field
ValidationFile respjson.Field
WandbProjectName respjson.Field
WandbURL respjson.Field
WarmupRatio respjson.Field
WeightDecay respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneResponse) RawJSON() string { return r.JSON.raw }
func (r *FinetuneResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneResponseStatus string
const (
FinetuneResponseStatusPending FinetuneResponseStatus = "pending"
FinetuneResponseStatusQueued FinetuneResponseStatus = "queued"
FinetuneResponseStatusRunning FinetuneResponseStatus = "running"
FinetuneResponseStatusCompressing FinetuneResponseStatus = "compressing"
FinetuneResponseStatusUploading FinetuneResponseStatus = "uploading"
FinetuneResponseStatusCancelRequested FinetuneResponseStatus = "cancel_requested"
FinetuneResponseStatusCancelled FinetuneResponseStatus = "cancelled"
FinetuneResponseStatusError FinetuneResponseStatus = "error"
FinetuneResponseStatusCompleted FinetuneResponseStatus = "completed"
)
// FinetuneResponseBatchSizeUnion contains all possible properties and values from
// [int64], [string].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfInt OfFinetuneResponseBatchSizeString]
type FinetuneResponseBatchSizeUnion struct {
// This field will be present if the value is a [int64] instead of an object.
OfInt int64 `json:",inline"`
// This field will be present if the value is a [string] instead of an object.
OfFinetuneResponseBatchSizeString string `json:",inline"`
JSON struct {
OfInt respjson.Field
OfFinetuneResponseBatchSizeString respjson.Field
raw string
} `json:"-"`
}
func (u FinetuneResponseBatchSizeUnion) AsInt() (v int64) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FinetuneResponseBatchSizeUnion) AsFinetuneResponseBatchSizeString() (v string) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FinetuneResponseBatchSizeUnion) RawJSON() string { return u.JSON.raw }
func (r *FinetuneResponseBatchSizeUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneResponseBatchSizeString string
const (
FinetuneResponseBatchSizeStringMax FinetuneResponseBatchSizeString = "max"
)
type FinetuneResponseLrScheduler struct {
// Any of "linear", "cosine".
LrSchedulerType string `json:"lr_scheduler_type" api:"required"`
LrSchedulerArgs FinetuneResponseLrSchedulerLrSchedulerArgsUnion `json:"lr_scheduler_args"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
LrSchedulerType respjson.Field
LrSchedulerArgs respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneResponseLrScheduler) RawJSON() string { return r.JSON.raw }
func (r *FinetuneResponseLrScheduler) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FinetuneResponseLrSchedulerLrSchedulerArgsUnion contains all possible properties
// and values from
// [FinetuneResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs],
// [FinetuneResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type FinetuneResponseLrSchedulerLrSchedulerArgsUnion struct {
MinLrRatio float64 `json:"min_lr_ratio"`
// This field is from variant
// [FinetuneResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs].
NumCycles float64 `json:"num_cycles"`
JSON struct {
MinLrRatio respjson.Field
NumCycles respjson.Field
raw string
} `json:"-"`
}
func (u FinetuneResponseLrSchedulerLrSchedulerArgsUnion) AsFinetuneResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs() (v FinetuneResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FinetuneResponseLrSchedulerLrSchedulerArgsUnion) AsFinetuneResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs() (v FinetuneResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FinetuneResponseLrSchedulerLrSchedulerArgsUnion) RawJSON() string { return u.JSON.raw }
func (r *FinetuneResponseLrSchedulerLrSchedulerArgsUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs struct {
// The ratio of the final learning rate to the peak learning rate
MinLrRatio float64 `json:"min_lr_ratio"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
MinLrRatio respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs) RawJSON() string {
return r.JSON.raw
}
func (r *FinetuneResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs struct {
// The ratio of the final learning rate to the peak learning rate
MinLrRatio float64 `json:"min_lr_ratio" api:"required"`
// Number or fraction of cycles for the cosine learning rate scheduler
NumCycles float64 `json:"num_cycles" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
MinLrRatio respjson.Field
NumCycles respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs) RawJSON() string {
return r.JSON.raw
}
func (r *FinetuneResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneResponseMultimodalParams struct {
// Whether to train the vision encoder of the model. Only available for multimodal
// models.
TrainVision bool `json:"train_vision"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
TrainVision respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneResponseMultimodalParams) RawJSON() string { return r.JSON.raw }
func (r *FinetuneResponseMultimodalParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Progress information for a fine-tuning job
type FinetuneResponseProgress struct {
// Whether time estimate is available
EstimateAvailable bool `json:"estimate_available" api:"required"`
// Estimated time remaining in seconds for the fine-tuning job to next state
SecondsRemaining int64 `json:"seconds_remaining" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
EstimateAvailable respjson.Field
SecondsRemaining respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneResponseProgress) RawJSON() string { return r.JSON.raw }
func (r *FinetuneResponseProgress) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FinetuneResponseTrainOnInputsUnion contains all possible properties and values
// from [bool], [string].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfBool OfFinetuneResponseTrainOnInputsString]
type FinetuneResponseTrainOnInputsUnion struct {
// This field will be present if the value is a [bool] instead of an object.
OfBool bool `json:",inline"`
// This field will be present if the value is a [string] instead of an object.
OfFinetuneResponseTrainOnInputsString string `json:",inline"`
JSON struct {
OfBool respjson.Field
OfFinetuneResponseTrainOnInputsString respjson.Field
raw string
} `json:"-"`
}
func (u FinetuneResponseTrainOnInputsUnion) AsBool() (v bool) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FinetuneResponseTrainOnInputsUnion) AsFinetuneResponseTrainOnInputsString() (v string) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FinetuneResponseTrainOnInputsUnion) RawJSON() string { return u.JSON.raw }
func (r *FinetuneResponseTrainOnInputsUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneResponseTrainOnInputsString string
const (
FinetuneResponseTrainOnInputsStringAuto FinetuneResponseTrainOnInputsString = "auto"
)
// FinetuneResponseTrainingMethodUnion contains all possible properties and values
// from [FinetuneResponseTrainingMethodTrainingMethodSft],
// [FinetuneResponseTrainingMethodTrainingMethodDpo].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type FinetuneResponseTrainingMethodUnion struct {
Method string `json:"method"`
// This field is from variant [FinetuneResponseTrainingMethodTrainingMethodSft].
TrainOnInputs FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsUnion `json:"train_on_inputs"`
// This field is from variant [FinetuneResponseTrainingMethodTrainingMethodDpo].
DpoBeta float64 `json:"dpo_beta"`
// This field is from variant [FinetuneResponseTrainingMethodTrainingMethodDpo].
DpoNormalizeLogratiosByLength bool `json:"dpo_normalize_logratios_by_length"`
// This field is from variant [FinetuneResponseTrainingMethodTrainingMethodDpo].
DpoReferenceFree bool `json:"dpo_reference_free"`
// This field is from variant [FinetuneResponseTrainingMethodTrainingMethodDpo].
RpoAlpha float64 `json:"rpo_alpha"`
// This field is from variant [FinetuneResponseTrainingMethodTrainingMethodDpo].
SimpoGamma float64 `json:"simpo_gamma"`
JSON struct {
Method respjson.Field
TrainOnInputs respjson.Field
DpoBeta respjson.Field
DpoNormalizeLogratiosByLength respjson.Field
DpoReferenceFree respjson.Field
RpoAlpha respjson.Field
SimpoGamma respjson.Field
raw string
} `json:"-"`
}
func (u FinetuneResponseTrainingMethodUnion) AsFinetuneResponseTrainingMethodTrainingMethodSft() (v FinetuneResponseTrainingMethodTrainingMethodSft) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FinetuneResponseTrainingMethodUnion) AsFinetuneResponseTrainingMethodTrainingMethodDpo() (v FinetuneResponseTrainingMethodTrainingMethodDpo) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FinetuneResponseTrainingMethodUnion) RawJSON() string { return u.JSON.raw }
func (r *FinetuneResponseTrainingMethodUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneResponseTrainingMethodTrainingMethodSft struct {
// Any of "sft".
Method string `json:"method" api:"required"`
// Whether to mask the user messages in conversational data or prompts in
// instruction data.
TrainOnInputs FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsUnion `json:"train_on_inputs" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Method respjson.Field
TrainOnInputs respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneResponseTrainingMethodTrainingMethodSft) RawJSON() string { return r.JSON.raw }
func (r *FinetuneResponseTrainingMethodTrainingMethodSft) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsUnion contains all
// possible properties and values from [bool], [string].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfBool
// OfFinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsString]
type FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsUnion struct {
// This field will be present if the value is a [bool] instead of an object.
OfBool bool `json:",inline"`
// This field will be present if the value is a [string] instead of an object.
OfFinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsString string `json:",inline"`
JSON struct {
OfBool respjson.Field
OfFinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsString respjson.Field
raw string
} `json:"-"`
}
func (u FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsUnion) AsBool() (v bool) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsUnion) AsFinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsString() (v string) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsUnion) RawJSON() string {
return u.JSON.raw
}
func (r *FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsString string
const (
FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsStringAuto FinetuneResponseTrainingMethodTrainingMethodSftTrainOnInputsString = "auto"
)
type FinetuneResponseTrainingMethodTrainingMethodDpo struct {
// Any of "dpo".
Method string `json:"method" api:"required"`
DpoBeta float64 `json:"dpo_beta"`
DpoNormalizeLogratiosByLength bool `json:"dpo_normalize_logratios_by_length"`
DpoReferenceFree bool `json:"dpo_reference_free"`
RpoAlpha float64 `json:"rpo_alpha"`
SimpoGamma float64 `json:"simpo_gamma"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Method respjson.Field
DpoBeta respjson.Field
DpoNormalizeLogratiosByLength respjson.Field
DpoReferenceFree respjson.Field
RpoAlpha respjson.Field
SimpoGamma respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneResponseTrainingMethodTrainingMethodDpo) RawJSON() string { return r.JSON.raw }
func (r *FinetuneResponseTrainingMethodTrainingMethodDpo) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FinetuneResponseTrainingTypeUnion contains all possible properties and values
// from [FinetuneResponseTrainingTypeFullTrainingType],
// [FinetuneResponseTrainingTypeLoRaTrainingType].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type FinetuneResponseTrainingTypeUnion struct {
Type string `json:"type"`
// This field is from variant [FinetuneResponseTrainingTypeLoRaTrainingType].
LoraAlpha int64 `json:"lora_alpha"`
// This field is from variant [FinetuneResponseTrainingTypeLoRaTrainingType].
LoraR int64 `json:"lora_r"`
// This field is from variant [FinetuneResponseTrainingTypeLoRaTrainingType].
LoraDropout float64 `json:"lora_dropout"`
// This field is from variant [FinetuneResponseTrainingTypeLoRaTrainingType].
LoraTrainableModules string `json:"lora_trainable_modules"`
JSON struct {
Type respjson.Field
LoraAlpha respjson.Field
LoraR respjson.Field
LoraDropout respjson.Field
LoraTrainableModules respjson.Field
raw string
} `json:"-"`
}
func (u FinetuneResponseTrainingTypeUnion) AsFinetuneResponseTrainingTypeFullTrainingType() (v FinetuneResponseTrainingTypeFullTrainingType) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FinetuneResponseTrainingTypeUnion) AsFinetuneResponseTrainingTypeLoRaTrainingType() (v FinetuneResponseTrainingTypeLoRaTrainingType) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FinetuneResponseTrainingTypeUnion) RawJSON() string { return u.JSON.raw }
func (r *FinetuneResponseTrainingTypeUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneResponseTrainingTypeFullTrainingType struct {
// Any of "Full".
Type string `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneResponseTrainingTypeFullTrainingType) RawJSON() string { return r.JSON.raw }
func (r *FinetuneResponseTrainingTypeFullTrainingType) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FinetuneResponseTrainingTypeLoRaTrainingType struct {
LoraAlpha int64 `json:"lora_alpha" api:"required"`
LoraR int64 `json:"lora_r" api:"required"`
// Any of "Lora".
Type string `json:"type" api:"required"`
LoraDropout float64 `json:"lora_dropout"`
LoraTrainableModules string `json:"lora_trainable_modules"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
LoraAlpha respjson.Field
LoraR respjson.Field
Type respjson.Field
LoraDropout respjson.Field
LoraTrainableModules respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FinetuneResponseTrainingTypeLoRaTrainingType) RawJSON() string { return r.JSON.raw }
func (r *FinetuneResponseTrainingTypeLoRaTrainingType) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A truncated version of the fine-tune response, used for POST /fine-tunes, GET
// /fine-tunes and POST /fine-tunes/{id}/cancel endpoints
type FineTuningNewResponse struct {
// Unique identifier for the fine-tune job
ID string `json:"id" api:"required"`
// Creation timestamp of the fine-tune job
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
// Any of "pending", "queued", "running", "compressing", "uploading",
// "cancel_requested", "cancelled", "error", "completed".
Status FineTuningNewResponseStatus `json:"status" api:"required"`
// Last update timestamp of the fine-tune job
UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"`
// Batch size used for training
BatchSize int64 `json:"batch_size"`
// Events related to this fine-tune job
Events []FinetuneEvent `json:"events"`
// Checkpoint used to continue training
FromCheckpoint string `json:"from_checkpoint"`
// Hugging Face Hub repo to start training from
FromHfModel string `json:"from_hf_model"`
// The revision of the Hugging Face Hub model to continue training from
HfModelRevision string `json:"hf_model_revision"`
// Learning rate used for training
LearningRate float64 `json:"learning_rate"`
// Learning rate scheduler configuration
LrScheduler FineTuningNewResponseLrScheduler `json:"lr_scheduler"`
// Maximum gradient norm for clipping
MaxGradNorm float64 `json:"max_grad_norm"`
// Base model used for fine-tuning
Model string `json:"model"`
ModelOutputName string `json:"model_output_name"`
// Number of checkpoints saved during training
NCheckpoints int64 `json:"n_checkpoints"`
// Number of training epochs
NEpochs int64 `json:"n_epochs"`
// Number of evaluations during training
NEvals int64 `json:"n_evals"`
// Owner address information
OwnerAddress string `json:"owner_address"`
// Whether sequence packing is being used for training.
Packing bool `json:"packing"`
// Progress information for the fine-tuning job
Progress FineTuningNewResponseProgress `json:"progress"`
// Random seed used for training. Integer when set; null if not stored (e.g. legacy
// jobs) or no explicit seed was recorded.
RandomSeed int64 `json:"random_seed" api:"nullable"`
// Start timestamp of the current stage of the fine-tune job
StartedAt time.Time `json:"started_at" format:"date-time"`
// Suffix added to the fine-tuned model name
Suffix string `json:"suffix"`
// Count of tokens processed
TokenCount int64 `json:"token_count"`
// Total price for the fine-tuning job
TotalPrice int64 `json:"total_price"`
// File-ID of the training file
TrainingFile string `json:"training_file"`
// Method of training used
TrainingMethod FineTuningNewResponseTrainingMethodUnion `json:"training_method"`
// Type of training used (full or LoRA)
TrainingType FineTuningNewResponseTrainingTypeUnion `json:"training_type"`
// Identifier for the user who created the job
UserID string `json:"user_id"`
// File-ID of the validation file
ValidationFile string `json:"validation_file"`
// Weights & Biases run name
WandbName string `json:"wandb_name"`
// Weights & Biases project name
WandbProjectName string `json:"wandb_project_name"`
// Ratio of warmup steps
WarmupRatio float64 `json:"warmup_ratio"`
// Weight decay value used
WeightDecay float64 `json:"weight_decay"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
CreatedAt respjson.Field
Status respjson.Field
UpdatedAt respjson.Field
BatchSize respjson.Field
Events respjson.Field
FromCheckpoint respjson.Field
FromHfModel respjson.Field
HfModelRevision respjson.Field
LearningRate respjson.Field
LrScheduler respjson.Field
MaxGradNorm respjson.Field
Model respjson.Field
ModelOutputName respjson.Field
NCheckpoints respjson.Field
NEpochs respjson.Field
NEvals respjson.Field
OwnerAddress respjson.Field
Packing respjson.Field
Progress respjson.Field
RandomSeed respjson.Field
StartedAt respjson.Field
Suffix respjson.Field
TokenCount respjson.Field
TotalPrice respjson.Field
TrainingFile respjson.Field
TrainingMethod respjson.Field
TrainingType respjson.Field
UserID respjson.Field
ValidationFile respjson.Field
WandbName respjson.Field
WandbProjectName respjson.Field
WarmupRatio respjson.Field
WeightDecay respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningNewResponse) RawJSON() string { return r.JSON.raw }
func (r *FineTuningNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FineTuningNewResponseStatus string
const (
FineTuningNewResponseStatusPending FineTuningNewResponseStatus = "pending"
FineTuningNewResponseStatusQueued FineTuningNewResponseStatus = "queued"
FineTuningNewResponseStatusRunning FineTuningNewResponseStatus = "running"
FineTuningNewResponseStatusCompressing FineTuningNewResponseStatus = "compressing"
FineTuningNewResponseStatusUploading FineTuningNewResponseStatus = "uploading"
FineTuningNewResponseStatusCancelRequested FineTuningNewResponseStatus = "cancel_requested"
FineTuningNewResponseStatusCancelled FineTuningNewResponseStatus = "cancelled"
FineTuningNewResponseStatusError FineTuningNewResponseStatus = "error"
FineTuningNewResponseStatusCompleted FineTuningNewResponseStatus = "completed"
)
// Learning rate scheduler configuration
type FineTuningNewResponseLrScheduler struct {
// Any of "linear", "cosine".
LrSchedulerType string `json:"lr_scheduler_type" api:"required"`
LrSchedulerArgs FineTuningNewResponseLrSchedulerLrSchedulerArgsUnion `json:"lr_scheduler_args"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
LrSchedulerType respjson.Field
LrSchedulerArgs respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningNewResponseLrScheduler) RawJSON() string { return r.JSON.raw }
func (r *FineTuningNewResponseLrScheduler) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// FineTuningNewResponseLrSchedulerLrSchedulerArgsUnion contains all possible
// properties and values from
// [FineTuningNewResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs],
// [FineTuningNewResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type FineTuningNewResponseLrSchedulerLrSchedulerArgsUnion struct {
MinLrRatio float64 `json:"min_lr_ratio"`
// This field is from variant
// [FineTuningNewResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs].
NumCycles float64 `json:"num_cycles"`
JSON struct {
MinLrRatio respjson.Field
NumCycles respjson.Field
raw string
} `json:"-"`
}
func (u FineTuningNewResponseLrSchedulerLrSchedulerArgsUnion) AsFineTuningNewResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs() (v FineTuningNewResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u FineTuningNewResponseLrSchedulerLrSchedulerArgsUnion) AsFineTuningNewResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs() (v FineTuningNewResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u FineTuningNewResponseLrSchedulerLrSchedulerArgsUnion) RawJSON() string { return u.JSON.raw }
func (r *FineTuningNewResponseLrSchedulerLrSchedulerArgsUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FineTuningNewResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs struct {
// The ratio of the final learning rate to the peak learning rate
MinLrRatio float64 `json:"min_lr_ratio"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
MinLrRatio respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FineTuningNewResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs) RawJSON() string {
return r.JSON.raw
}
func (r *FineTuningNewResponseLrSchedulerLrSchedulerArgsLinearLrSchedulerArgs) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FineTuningNewResponseLrSchedulerLrSchedulerArgsCosineLrSchedulerArgs struct {
// The ratio of the final learning rate to the peak learning rate
MinLrRatio float64 `json:"min_lr_ratio" api:"required"`
// Number or fraction of cycles for the cosine learning rate scheduler
NumCycles float64 `json:"num_cycles" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
MinLrRatio respjson.Field
NumCycles respjson.Field
ExtraFields map[string]respjson.Field