-
Notifications
You must be signed in to change notification settings - Fork 35
/
finetuningjob.go
1594 lines (1376 loc) · 58.2 KB
/
finetuningjob.go
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 openai
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"reflect"
"github.com/openai/openai-go/internal/apijson"
"github.com/openai/openai-go/internal/apiquery"
"github.com/openai/openai-go/internal/param"
"github.com/openai/openai-go/internal/requestconfig"
"github.com/openai/openai-go/option"
"github.com/openai/openai-go/packages/pagination"
"github.com/openai/openai-go/shared"
"github.com/tidwall/gjson"
)
// FineTuningJobService contains methods and other services that help with
// interacting with the openai 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 [NewFineTuningJobService] method instead.
type FineTuningJobService struct {
Options []option.RequestOption
Checkpoints *FineTuningJobCheckpointService
}
// NewFineTuningJobService 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 NewFineTuningJobService(opts ...option.RequestOption) (r *FineTuningJobService) {
r = &FineTuningJobService{}
r.Options = opts
r.Checkpoints = NewFineTuningJobCheckpointService(opts...)
return
}
// Creates a fine-tuning job which begins the process of creating a new model from
// a given dataset.
//
// Response includes details of the enqueued job including job status and the name
// of the fine-tuned models once complete.
//
// [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
func (r *FineTuningJobService) New(ctx context.Context, body FineTuningJobNewParams, opts ...option.RequestOption) (res *FineTuningJob, err error) {
opts = append(r.Options[:], opts...)
path := "fine_tuning/jobs"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Get info about a fine-tuning job.
//
// [Learn more about fine-tuning](https://platform.openai.com/docs/guides/fine-tuning)
func (r *FineTuningJobService) Get(ctx context.Context, fineTuningJobID string, opts ...option.RequestOption) (res *FineTuningJob, err error) {
opts = append(r.Options[:], opts...)
if fineTuningJobID == "" {
err = errors.New("missing required fine_tuning_job_id parameter")
return
}
path := fmt.Sprintf("fine_tuning/jobs/%s", fineTuningJobID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// List your organization's fine-tuning jobs
func (r *FineTuningJobService) List(ctx context.Context, query FineTuningJobListParams, opts ...option.RequestOption) (res *pagination.CursorPage[FineTuningJob], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "fine_tuning/jobs"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List your organization's fine-tuning jobs
func (r *FineTuningJobService) ListAutoPaging(ctx context.Context, query FineTuningJobListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[FineTuningJob] {
return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
}
// Immediately cancel a fine-tune job.
func (r *FineTuningJobService) Cancel(ctx context.Context, fineTuningJobID string, opts ...option.RequestOption) (res *FineTuningJob, err error) {
opts = append(r.Options[:], opts...)
if fineTuningJobID == "" {
err = errors.New("missing required fine_tuning_job_id parameter")
return
}
path := fmt.Sprintf("fine_tuning/jobs/%s/cancel", fineTuningJobID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
// Get status updates for a fine-tuning job.
func (r *FineTuningJobService) ListEvents(ctx context.Context, fineTuningJobID string, query FineTuningJobListEventsParams, opts ...option.RequestOption) (res *pagination.CursorPage[FineTuningJobEvent], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if fineTuningJobID == "" {
err = errors.New("missing required fine_tuning_job_id parameter")
return
}
path := fmt.Sprintf("fine_tuning/jobs/%s/events", fineTuningJobID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Get status updates for a fine-tuning job.
func (r *FineTuningJobService) ListEventsAutoPaging(ctx context.Context, fineTuningJobID string, query FineTuningJobListEventsParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[FineTuningJobEvent] {
return pagination.NewCursorPageAutoPager(r.ListEvents(ctx, fineTuningJobID, query, opts...))
}
// The `fine_tuning.job` object represents a fine-tuning job that has been created
// through the API.
type FineTuningJob struct {
// The object identifier, which can be referenced in the API endpoints.
ID string `json:"id,required"`
// The Unix timestamp (in seconds) for when the fine-tuning job was created.
CreatedAt int64 `json:"created_at,required"`
// For fine-tuning jobs that have `failed`, this will contain more information on
// the cause of the failure.
Error FineTuningJobError `json:"error,required,nullable"`
// The name of the fine-tuned model that is being created. The value will be null
// if the fine-tuning job is still running.
FineTunedModel string `json:"fine_tuned_model,required,nullable"`
// The Unix timestamp (in seconds) for when the fine-tuning job was finished. The
// value will be null if the fine-tuning job is still running.
FinishedAt int64 `json:"finished_at,required,nullable"`
// The hyperparameters used for the fine-tuning job. This value will only be
// returned when running `supervised` jobs.
Hyperparameters FineTuningJobHyperparameters `json:"hyperparameters,required"`
// The base model that is being fine-tuned.
Model string `json:"model,required"`
// The object type, which is always "fine_tuning.job".
Object FineTuningJobObject `json:"object,required"`
// The organization that owns the fine-tuning job.
OrganizationID string `json:"organization_id,required"`
// The compiled results file ID(s) for the fine-tuning job. You can retrieve the
// results with the
// [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).
ResultFiles []string `json:"result_files,required"`
// The seed used for the fine-tuning job.
Seed int64 `json:"seed,required"`
// The current status of the fine-tuning job, which can be either
// `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`.
Status FineTuningJobStatus `json:"status,required"`
// The total number of billable tokens processed by this fine-tuning job. The value
// will be null if the fine-tuning job is still running.
TrainedTokens int64 `json:"trained_tokens,required,nullable"`
// The file ID used for training. You can retrieve the training data with the
// [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).
TrainingFile string `json:"training_file,required"`
// The file ID used for validation. You can retrieve the validation results with
// the
// [Files API](https://platform.openai.com/docs/api-reference/files/retrieve-contents).
ValidationFile string `json:"validation_file,required,nullable"`
// The Unix timestamp (in seconds) for when the fine-tuning job is estimated to
// finish. The value will be null if the fine-tuning job is not running.
EstimatedFinish int64 `json:"estimated_finish,nullable"`
// A list of integrations to enable for this fine-tuning job.
Integrations []FineTuningJobWandbIntegrationObject `json:"integrations,nullable"`
// The method used for fine-tuning.
Method FineTuningJobMethod `json:"method"`
JSON fineTuningJobJSON `json:"-"`
}
// fineTuningJobJSON contains the JSON metadata for the struct [FineTuningJob]
type fineTuningJobJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Error apijson.Field
FineTunedModel apijson.Field
FinishedAt apijson.Field
Hyperparameters apijson.Field
Model apijson.Field
Object apijson.Field
OrganizationID apijson.Field
ResultFiles apijson.Field
Seed apijson.Field
Status apijson.Field
TrainedTokens apijson.Field
TrainingFile apijson.Field
ValidationFile apijson.Field
EstimatedFinish apijson.Field
Integrations apijson.Field
Method apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJob) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobJSON) RawJSON() string {
return r.raw
}
// For fine-tuning jobs that have `failed`, this will contain more information on
// the cause of the failure.
type FineTuningJobError struct {
// A machine-readable error code.
Code string `json:"code,required"`
// A human-readable error message.
Message string `json:"message,required"`
// The parameter that was invalid, usually `training_file` or `validation_file`.
// This field will be null if the failure was not parameter-specific.
Param string `json:"param,required,nullable"`
JSON fineTuningJobErrorJSON `json:"-"`
}
// fineTuningJobErrorJSON contains the JSON metadata for the struct
// [FineTuningJobError]
type fineTuningJobErrorJSON struct {
Code apijson.Field
Message apijson.Field
Param apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobErrorJSON) RawJSON() string {
return r.raw
}
// The hyperparameters used for the fine-tuning job. This value will only be
// returned when running `supervised` jobs.
type FineTuningJobHyperparameters struct {
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
BatchSize FineTuningJobHyperparametersBatchSizeUnion `json:"batch_size"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
LearningRateMultiplier FineTuningJobHyperparametersLearningRateMultiplierUnion `json:"learning_rate_multiplier"`
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
NEpochs FineTuningJobHyperparametersNEpochsUnion `json:"n_epochs"`
JSON fineTuningJobHyperparametersJSON `json:"-"`
}
// fineTuningJobHyperparametersJSON contains the JSON metadata for the struct
// [FineTuningJobHyperparameters]
type fineTuningJobHyperparametersJSON struct {
BatchSize apijson.Field
LearningRateMultiplier apijson.Field
NEpochs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobHyperparameters) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobHyperparametersJSON) RawJSON() string {
return r.raw
}
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
//
// Union satisfied by [FineTuningJobHyperparametersBatchSizeAuto] or
// [shared.UnionInt].
type FineTuningJobHyperparametersBatchSizeUnion interface {
ImplementsFineTuningJobHyperparametersBatchSizeUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*FineTuningJobHyperparametersBatchSizeUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(FineTuningJobHyperparametersBatchSizeAuto("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionInt(0)),
},
)
}
type FineTuningJobHyperparametersBatchSizeAuto string
const (
FineTuningJobHyperparametersBatchSizeAutoAuto FineTuningJobHyperparametersBatchSizeAuto = "auto"
)
func (r FineTuningJobHyperparametersBatchSizeAuto) IsKnown() bool {
switch r {
case FineTuningJobHyperparametersBatchSizeAutoAuto:
return true
}
return false
}
func (r FineTuningJobHyperparametersBatchSizeAuto) ImplementsFineTuningJobHyperparametersBatchSizeUnion() {
}
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
//
// Union satisfied by [FineTuningJobHyperparametersLearningRateMultiplierAuto] or
// [shared.UnionFloat].
type FineTuningJobHyperparametersLearningRateMultiplierUnion interface {
ImplementsFineTuningJobHyperparametersLearningRateMultiplierUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*FineTuningJobHyperparametersLearningRateMultiplierUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(FineTuningJobHyperparametersLearningRateMultiplierAuto("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type FineTuningJobHyperparametersLearningRateMultiplierAuto string
const (
FineTuningJobHyperparametersLearningRateMultiplierAutoAuto FineTuningJobHyperparametersLearningRateMultiplierAuto = "auto"
)
func (r FineTuningJobHyperparametersLearningRateMultiplierAuto) IsKnown() bool {
switch r {
case FineTuningJobHyperparametersLearningRateMultiplierAutoAuto:
return true
}
return false
}
func (r FineTuningJobHyperparametersLearningRateMultiplierAuto) ImplementsFineTuningJobHyperparametersLearningRateMultiplierUnion() {
}
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
//
// Union satisfied by [FineTuningJobHyperparametersNEpochsBehavior] or
// [shared.UnionInt].
type FineTuningJobHyperparametersNEpochsUnion interface {
ImplementsFineTuningJobHyperparametersNEpochsUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*FineTuningJobHyperparametersNEpochsUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(FineTuningJobHyperparametersNEpochsBehavior("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionInt(0)),
},
)
}
type FineTuningJobHyperparametersNEpochsBehavior string
const (
FineTuningJobHyperparametersNEpochsBehaviorAuto FineTuningJobHyperparametersNEpochsBehavior = "auto"
)
func (r FineTuningJobHyperparametersNEpochsBehavior) IsKnown() bool {
switch r {
case FineTuningJobHyperparametersNEpochsBehaviorAuto:
return true
}
return false
}
func (r FineTuningJobHyperparametersNEpochsBehavior) ImplementsFineTuningJobHyperparametersNEpochsUnion() {
}
// The object type, which is always "fine_tuning.job".
type FineTuningJobObject string
const (
FineTuningJobObjectFineTuningJob FineTuningJobObject = "fine_tuning.job"
)
func (r FineTuningJobObject) IsKnown() bool {
switch r {
case FineTuningJobObjectFineTuningJob:
return true
}
return false
}
// The current status of the fine-tuning job, which can be either
// `validating_files`, `queued`, `running`, `succeeded`, `failed`, or `cancelled`.
type FineTuningJobStatus string
const (
FineTuningJobStatusValidatingFiles FineTuningJobStatus = "validating_files"
FineTuningJobStatusQueued FineTuningJobStatus = "queued"
FineTuningJobStatusRunning FineTuningJobStatus = "running"
FineTuningJobStatusSucceeded FineTuningJobStatus = "succeeded"
FineTuningJobStatusFailed FineTuningJobStatus = "failed"
FineTuningJobStatusCancelled FineTuningJobStatus = "cancelled"
)
func (r FineTuningJobStatus) IsKnown() bool {
switch r {
case FineTuningJobStatusValidatingFiles, FineTuningJobStatusQueued, FineTuningJobStatusRunning, FineTuningJobStatusSucceeded, FineTuningJobStatusFailed, FineTuningJobStatusCancelled:
return true
}
return false
}
// The method used for fine-tuning.
type FineTuningJobMethod struct {
// Configuration for the DPO fine-tuning method.
Dpo FineTuningJobMethodDpo `json:"dpo"`
// Configuration for the supervised fine-tuning method.
Supervised FineTuningJobMethodSupervised `json:"supervised"`
// The type of method. Is either `supervised` or `dpo`.
Type FineTuningJobMethodType `json:"type"`
JSON fineTuningJobMethodJSON `json:"-"`
}
// fineTuningJobMethodJSON contains the JSON metadata for the struct
// [FineTuningJobMethod]
type fineTuningJobMethodJSON struct {
Dpo apijson.Field
Supervised apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobMethod) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobMethodJSON) RawJSON() string {
return r.raw
}
// Configuration for the DPO fine-tuning method.
type FineTuningJobMethodDpo struct {
// The hyperparameters used for the fine-tuning job.
Hyperparameters FineTuningJobMethodDpoHyperparameters `json:"hyperparameters"`
JSON fineTuningJobMethodDpoJSON `json:"-"`
}
// fineTuningJobMethodDpoJSON contains the JSON metadata for the struct
// [FineTuningJobMethodDpo]
type fineTuningJobMethodDpoJSON struct {
Hyperparameters apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobMethodDpo) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobMethodDpoJSON) RawJSON() string {
return r.raw
}
// The hyperparameters used for the fine-tuning job.
type FineTuningJobMethodDpoHyperparameters struct {
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
BatchSize FineTuningJobMethodDpoHyperparametersBatchSizeUnion `json:"batch_size"`
// The beta value for the DPO method. A higher beta value will increase the weight
// of the penalty between the policy and reference model.
Beta FineTuningJobMethodDpoHyperparametersBetaUnion `json:"beta"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
LearningRateMultiplier FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion `json:"learning_rate_multiplier"`
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
NEpochs FineTuningJobMethodDpoHyperparametersNEpochsUnion `json:"n_epochs"`
JSON fineTuningJobMethodDpoHyperparametersJSON `json:"-"`
}
// fineTuningJobMethodDpoHyperparametersJSON contains the JSON metadata for the
// struct [FineTuningJobMethodDpoHyperparameters]
type fineTuningJobMethodDpoHyperparametersJSON struct {
BatchSize apijson.Field
Beta apijson.Field
LearningRateMultiplier apijson.Field
NEpochs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobMethodDpoHyperparameters) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobMethodDpoHyperparametersJSON) RawJSON() string {
return r.raw
}
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
//
// Union satisfied by [FineTuningJobMethodDpoHyperparametersBatchSizeAuto] or
// [shared.UnionInt].
type FineTuningJobMethodDpoHyperparametersBatchSizeUnion interface {
ImplementsFineTuningJobMethodDpoHyperparametersBatchSizeUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*FineTuningJobMethodDpoHyperparametersBatchSizeUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(FineTuningJobMethodDpoHyperparametersBatchSizeAuto("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionInt(0)),
},
)
}
type FineTuningJobMethodDpoHyperparametersBatchSizeAuto string
const (
FineTuningJobMethodDpoHyperparametersBatchSizeAutoAuto FineTuningJobMethodDpoHyperparametersBatchSizeAuto = "auto"
)
func (r FineTuningJobMethodDpoHyperparametersBatchSizeAuto) IsKnown() bool {
switch r {
case FineTuningJobMethodDpoHyperparametersBatchSizeAutoAuto:
return true
}
return false
}
func (r FineTuningJobMethodDpoHyperparametersBatchSizeAuto) ImplementsFineTuningJobMethodDpoHyperparametersBatchSizeUnion() {
}
// The beta value for the DPO method. A higher beta value will increase the weight
// of the penalty between the policy and reference model.
//
// Union satisfied by [FineTuningJobMethodDpoHyperparametersBetaAuto] or
// [shared.UnionFloat].
type FineTuningJobMethodDpoHyperparametersBetaUnion interface {
ImplementsFineTuningJobMethodDpoHyperparametersBetaUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*FineTuningJobMethodDpoHyperparametersBetaUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(FineTuningJobMethodDpoHyperparametersBetaAuto("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type FineTuningJobMethodDpoHyperparametersBetaAuto string
const (
FineTuningJobMethodDpoHyperparametersBetaAutoAuto FineTuningJobMethodDpoHyperparametersBetaAuto = "auto"
)
func (r FineTuningJobMethodDpoHyperparametersBetaAuto) IsKnown() bool {
switch r {
case FineTuningJobMethodDpoHyperparametersBetaAutoAuto:
return true
}
return false
}
func (r FineTuningJobMethodDpoHyperparametersBetaAuto) ImplementsFineTuningJobMethodDpoHyperparametersBetaUnion() {
}
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
//
// Union satisfied by
// [FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto] or
// [shared.UnionFloat].
type FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion interface {
ImplementsFineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*FineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto string
const (
FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAutoAuto FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto = "auto"
)
func (r FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto) IsKnown() bool {
switch r {
case FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAutoAuto:
return true
}
return false
}
func (r FineTuningJobMethodDpoHyperparametersLearningRateMultiplierAuto) ImplementsFineTuningJobMethodDpoHyperparametersLearningRateMultiplierUnion() {
}
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
//
// Union satisfied by [FineTuningJobMethodDpoHyperparametersNEpochsAuto] or
// [shared.UnionInt].
type FineTuningJobMethodDpoHyperparametersNEpochsUnion interface {
ImplementsFineTuningJobMethodDpoHyperparametersNEpochsUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*FineTuningJobMethodDpoHyperparametersNEpochsUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(FineTuningJobMethodDpoHyperparametersNEpochsAuto("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionInt(0)),
},
)
}
type FineTuningJobMethodDpoHyperparametersNEpochsAuto string
const (
FineTuningJobMethodDpoHyperparametersNEpochsAutoAuto FineTuningJobMethodDpoHyperparametersNEpochsAuto = "auto"
)
func (r FineTuningJobMethodDpoHyperparametersNEpochsAuto) IsKnown() bool {
switch r {
case FineTuningJobMethodDpoHyperparametersNEpochsAutoAuto:
return true
}
return false
}
func (r FineTuningJobMethodDpoHyperparametersNEpochsAuto) ImplementsFineTuningJobMethodDpoHyperparametersNEpochsUnion() {
}
// Configuration for the supervised fine-tuning method.
type FineTuningJobMethodSupervised struct {
// The hyperparameters used for the fine-tuning job.
Hyperparameters FineTuningJobMethodSupervisedHyperparameters `json:"hyperparameters"`
JSON fineTuningJobMethodSupervisedJSON `json:"-"`
}
// fineTuningJobMethodSupervisedJSON contains the JSON metadata for the struct
// [FineTuningJobMethodSupervised]
type fineTuningJobMethodSupervisedJSON struct {
Hyperparameters apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobMethodSupervised) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobMethodSupervisedJSON) RawJSON() string {
return r.raw
}
// The hyperparameters used for the fine-tuning job.
type FineTuningJobMethodSupervisedHyperparameters struct {
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
BatchSize FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion `json:"batch_size"`
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
LearningRateMultiplier FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion `json:"learning_rate_multiplier"`
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
NEpochs FineTuningJobMethodSupervisedHyperparametersNEpochsUnion `json:"n_epochs"`
JSON fineTuningJobMethodSupervisedHyperparametersJSON `json:"-"`
}
// fineTuningJobMethodSupervisedHyperparametersJSON contains the JSON metadata for
// the struct [FineTuningJobMethodSupervisedHyperparameters]
type fineTuningJobMethodSupervisedHyperparametersJSON struct {
BatchSize apijson.Field
LearningRateMultiplier apijson.Field
NEpochs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobMethodSupervisedHyperparameters) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobMethodSupervisedHyperparametersJSON) RawJSON() string {
return r.raw
}
// Number of examples in each batch. A larger batch size means that model
// parameters are updated less frequently, but with lower variance.
//
// Union satisfied by [FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto]
// or [shared.UnionInt].
type FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion interface {
ImplementsFineTuningJobMethodSupervisedHyperparametersBatchSizeUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*FineTuningJobMethodSupervisedHyperparametersBatchSizeUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionInt(0)),
},
)
}
type FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto string
const (
FineTuningJobMethodSupervisedHyperparametersBatchSizeAutoAuto FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto = "auto"
)
func (r FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto) IsKnown() bool {
switch r {
case FineTuningJobMethodSupervisedHyperparametersBatchSizeAutoAuto:
return true
}
return false
}
func (r FineTuningJobMethodSupervisedHyperparametersBatchSizeAuto) ImplementsFineTuningJobMethodSupervisedHyperparametersBatchSizeUnion() {
}
// Scaling factor for the learning rate. A smaller learning rate may be useful to
// avoid overfitting.
//
// Union satisfied by
// [FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto] or
// [shared.UnionFloat].
type FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion interface {
ImplementsFineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto string
const (
FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAutoAuto FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto = "auto"
)
func (r FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto) IsKnown() bool {
switch r {
case FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAutoAuto:
return true
}
return false
}
func (r FineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierAuto) ImplementsFineTuningJobMethodSupervisedHyperparametersLearningRateMultiplierUnion() {
}
// The number of epochs to train the model for. An epoch refers to one full cycle
// through the training dataset.
//
// Union satisfied by [FineTuningJobMethodSupervisedHyperparametersNEpochsAuto] or
// [shared.UnionInt].
type FineTuningJobMethodSupervisedHyperparametersNEpochsUnion interface {
ImplementsFineTuningJobMethodSupervisedHyperparametersNEpochsUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*FineTuningJobMethodSupervisedHyperparametersNEpochsUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(FineTuningJobMethodSupervisedHyperparametersNEpochsAuto("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionInt(0)),
},
)
}
type FineTuningJobMethodSupervisedHyperparametersNEpochsAuto string
const (
FineTuningJobMethodSupervisedHyperparametersNEpochsAutoAuto FineTuningJobMethodSupervisedHyperparametersNEpochsAuto = "auto"
)
func (r FineTuningJobMethodSupervisedHyperparametersNEpochsAuto) IsKnown() bool {
switch r {
case FineTuningJobMethodSupervisedHyperparametersNEpochsAutoAuto:
return true
}
return false
}
func (r FineTuningJobMethodSupervisedHyperparametersNEpochsAuto) ImplementsFineTuningJobMethodSupervisedHyperparametersNEpochsUnion() {
}
// The type of method. Is either `supervised` or `dpo`.
type FineTuningJobMethodType string
const (
FineTuningJobMethodTypeSupervised FineTuningJobMethodType = "supervised"
FineTuningJobMethodTypeDpo FineTuningJobMethodType = "dpo"
)
func (r FineTuningJobMethodType) IsKnown() bool {
switch r {
case FineTuningJobMethodTypeSupervised, FineTuningJobMethodTypeDpo:
return true
}
return false
}
// Fine-tuning job event object
type FineTuningJobEvent struct {
// The object identifier.
ID string `json:"id,required"`
// The Unix timestamp (in seconds) for when the fine-tuning job was created.
CreatedAt int64 `json:"created_at,required"`
// The log level of the event.
Level FineTuningJobEventLevel `json:"level,required"`
// The message of the event.
Message string `json:"message,required"`
// The object type, which is always "fine_tuning.job.event".
Object FineTuningJobEventObject `json:"object,required"`
// The data associated with the event.
Data interface{} `json:"data"`
// The type of event.
Type FineTuningJobEventType `json:"type"`
JSON fineTuningJobEventJSON `json:"-"`
}
// fineTuningJobEventJSON contains the JSON metadata for the struct
// [FineTuningJobEvent]
type fineTuningJobEventJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Level apijson.Field
Message apijson.Field
Object apijson.Field
Data apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobEvent) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r fineTuningJobEventJSON) RawJSON() string {
return r.raw
}
// The log level of the event.
type FineTuningJobEventLevel string
const (
FineTuningJobEventLevelInfo FineTuningJobEventLevel = "info"
FineTuningJobEventLevelWarn FineTuningJobEventLevel = "warn"
FineTuningJobEventLevelError FineTuningJobEventLevel = "error"
)
func (r FineTuningJobEventLevel) IsKnown() bool {
switch r {
case FineTuningJobEventLevelInfo, FineTuningJobEventLevelWarn, FineTuningJobEventLevelError:
return true
}
return false
}
// The object type, which is always "fine_tuning.job.event".
type FineTuningJobEventObject string
const (
FineTuningJobEventObjectFineTuningJobEvent FineTuningJobEventObject = "fine_tuning.job.event"
)
func (r FineTuningJobEventObject) IsKnown() bool {
switch r {
case FineTuningJobEventObjectFineTuningJobEvent:
return true
}
return false
}
// The type of event.
type FineTuningJobEventType string
const (
FineTuningJobEventTypeMessage FineTuningJobEventType = "message"
FineTuningJobEventTypeMetrics FineTuningJobEventType = "metrics"
)
func (r FineTuningJobEventType) IsKnown() bool {
switch r {
case FineTuningJobEventTypeMessage, FineTuningJobEventTypeMetrics:
return true
}
return false
}
type FineTuningJobWandbIntegrationObject struct {
// The type of the integration being enabled for the fine-tuning job
Type FineTuningJobWandbIntegrationObjectType `json:"type,required"`
// The settings for your integration with Weights and Biases. This payload
// specifies the project that metrics will be sent to. Optionally, you can set an
// explicit display name for your run, add tags to your run, and set a default
// entity (team, username, etc) to be associated with your run.
Wandb FineTuningJobWandbIntegration `json:"wandb,required"`
JSON fineTuningJobWandbIntegrationObjectJSON `json:"-"`
}
// fineTuningJobWandbIntegrationObjectJSON contains the JSON metadata for the
// struct [FineTuningJobWandbIntegrationObject]
type fineTuningJobWandbIntegrationObjectJSON struct {
Type apijson.Field
Wandb apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *FineTuningJobWandbIntegrationObject) UnmarshalJSON(data []byte) (err error) {