Skip to content

Commit

Permalink
feat: Add Weights & Biases fine-tuning integration and seed in openai…
Browse files Browse the repository at this point in the history
…_dart (#377)
  • Loading branch information
davidmigloz committed Apr 12, 2024
1 parent 69f8e2f commit a5fff1b
Show file tree
Hide file tree
Showing 7 changed files with 899 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class CreateFineTuningJobRequest with _$CreateFineTuningJobRequest {
/// See the [fine-tuning guide](https://platform.openai.com/docs/guides/fine-tuning) for more details.
@JsonKey(name: 'validation_file', includeIfNull: false)
String? validationFile,

/// A list of integrations to enable for your fine-tuning job.
@JsonKey(includeIfNull: false) List<FineTuningIntegration>? integrations,

/// The seed controls the reproducibility of the job. Passing in the same seed and job parameters should produce the same results, but may differ in rare cases.
/// If a seed is not specified, one will be generated for you.
@JsonKey(includeIfNull: false) int? seed,
}) = _CreateFineTuningJobRequest;

/// Object construction from a JSON representation
Expand All @@ -61,12 +68,16 @@ class CreateFineTuningJobRequest with _$CreateFineTuningJobRequest {
'training_file',
'hyperparameters',
'suffix',
'validation_file'
'validation_file',
'integrations',
'seed'
];

/// Validation constants
static const suffixMinLengthValue = 1;
static const suffixMaxLengthValue = 40;
static const seedMinValue = 0;
static const seedMaxValue = 2147483647;

/// Perform validations on the schema property values
String? validateSchema() {
Expand All @@ -76,6 +87,12 @@ class CreateFineTuningJobRequest with _$CreateFineTuningJobRequest {
if (suffix != null && suffix!.length > suffixMaxLengthValue) {
return "The length of 'suffix' cannot be > $suffixMaxLengthValue characters";
}
if (seed != null && seed! < seedMinValue) {
return "The value of 'seed' cannot be < $seedMinValue";
}
if (seed != null && seed! > seedMaxValue) {
return "The value of 'seed' cannot be > $seedMaxValue";
}
return null;
}

Expand All @@ -87,6 +104,8 @@ class CreateFineTuningJobRequest with _$CreateFineTuningJobRequest {
'hyperparameters': hyperparameters,
'suffix': suffix,
'validation_file': validationFile,
'integrations': integrations,
'seed': seed,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
part of open_a_i_schema;

// ==========================================
// CLASS: FineTuningIntegration
// ==========================================

/// A fine-tuning integration to enable for a fine-tuning job.
@freezed
class FineTuningIntegration with _$FineTuningIntegration {
const FineTuningIntegration._();

/// Factory constructor for FineTuningIntegration
const factory FineTuningIntegration({
/// The type of integration to enable. Currently, only "wandb" (Weights and Biases) is supported.
required FineTuningIntegrationType type,

/// 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.
required FineTuningIntegrationWandb wandb,
}) = _FineTuningIntegration;

/// Object construction from a JSON representation
factory FineTuningIntegration.fromJson(Map<String, dynamic> json) =>
_$FineTuningIntegrationFromJson(json);

/// List of all property names of schema
static const List<String> propertyNames = ['type', 'wandb'];

/// Perform validations on the schema property values
String? validateSchema() {
return null;
}

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'type': type,
'wandb': wandb,
};
}
}

// ==========================================
// ENUM: FineTuningIntegrationType
// ==========================================

/// The type of integration to enable. Currently, only "wandb" (Weights and Biases) is supported.
enum FineTuningIntegrationType {
@JsonValue('wandb')
wandb,
}

// ==========================================
// CLASS: FineTuningIntegrationWandb
// ==========================================

/// 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.
@freezed
class FineTuningIntegrationWandb with _$FineTuningIntegrationWandb {
const FineTuningIntegrationWandb._();

/// Factory constructor for FineTuningIntegrationWandb
const factory FineTuningIntegrationWandb({
/// The name of the project that the new run will be created under.
required String project,

/// A display name to set for the run. If not set, we will use the Job ID as the name.
@JsonKey(includeIfNull: false) String? name,

/// The entity to use for the run. This allows you to set the team or username of the WandB user that you would
/// like associated with the run. If not set, the default entity for the registered WandB API key is used.
@JsonKey(includeIfNull: false) String? entity,

/// A list of tags to be attached to the newly created run. These tags are passed through directly to WandB. Some
/// default tags are generated by OpenAI: "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}".
@JsonKey(includeIfNull: false) List<String>? tags,
}) = _FineTuningIntegrationWandb;

/// Object construction from a JSON representation
factory FineTuningIntegrationWandb.fromJson(Map<String, dynamic> json) =>
_$FineTuningIntegrationWandbFromJson(json);

/// List of all property names of schema
static const List<String> propertyNames = [
'project',
'name',
'entity',
'tags'
];

/// Perform validations on the schema property values
String? validateSchema() {
return null;
}

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'project': project,
'name': name,
'entity': entity,
'tags': tags,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class FineTuningJob with _$FineTuningJob {

/// 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).
@JsonKey(name: 'validation_file') required String? validationFile,

/// A list of integrations to enable for this fine-tuning job.
@JsonKey(includeIfNull: false) List<FineTuningIntegration>? integrations,
}) = _FineTuningJob;

/// Object construction from a JSON representation
Expand All @@ -77,7 +80,8 @@ class FineTuningJob with _$FineTuningJob {
'status',
'trained_tokens',
'training_file',
'validation_file'
'validation_file',
'integrations'
];

/// Perform validations on the schema property values
Expand All @@ -102,6 +106,7 @@ class FineTuningJob with _$FineTuningJob {
'trained_tokens': trainedTokens,
'training_file': trainingFile,
'validation_file': validationFile,
'integrations': integrations,
};
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/openai_dart/lib/src/generated/schema/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ part 'embedding.dart';
part 'embedding_usage.dart';
part 'create_fine_tuning_job_request.dart';
part 'fine_tuning_job.dart';
part 'fine_tuning_integration.dart';
part 'fine_tuning_job_status.dart';
part 'fine_tuning_job_error.dart';
part 'fine_tuning_job_hyperparameters.dart';
Expand Down

0 comments on commit a5fff1b

Please sign in to comment.