Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tune): round fractional epoch in tune data points #363

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/types_generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def generate_models(schema_path: Path, output: Path, extra_template_data: Option
target_python_version=PythonVersion.PY_39,
base_class=ExtractorConfig.base_model_class,
additional_imports=[
"warnings",
"deprecated",
"pydantic.field_validator",
"pydantic.computed_field",
Expand Down
20 changes: 20 additions & 0 deletions scripts/types_generator/schema_aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -822,3 +822,23 @@ model_extensions:

PromptModerationParameters:
custom_base_class: ModerationParameters

TuneResultDatapointValidationLossData:
custom_body: |
@field_validator("epoch", mode="before")
@classmethod
def _validate_epoch(cls, value: Any):
result_value = int(value)
if result_value != float(value):
warnings.warn(f'The epoch was rounded down from {value} to {result_value}', stacklevel=4)
return result_value

TuneResultDatapointLossData:
custom_body: |
@field_validator("epoch", mode="before")
@classmethod
def _validate_epoch(cls, value: Any):
result_value = int(value)
if result_value != float(value):
warnings.warn(f'The epoch was rounded down from {value} to {result_value}', stacklevel=4)
return result_value
19 changes: 18 additions & 1 deletion src/genai/schema/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

from __future__ import annotations

import warnings
from datetime import date
from enum import Enum
from typing import Any, Literal, Optional, Union

from pydantic import AwareDatetime, Field, RootModel
from pydantic import AwareDatetime, Field, RootModel, field_validator

from genai._types import ApiBaseModel

Expand Down Expand Up @@ -2208,6 +2209,14 @@ class TuneResultDatapointLossData(ApiBaseModel):
step: Optional[int] = None
value: float

@field_validator("epoch", mode="before")
@classmethod
def _validate_epoch(cls, value: Any):
result_value = int(value)
if result_value != float(value):
warnings.warn(f"The epoch was rounded down from {value} to {result_value}", stacklevel=4)
return result_value


class TuneResultDatapointValidationLoss(ApiBaseModel):
data: TuneResultDatapointValidationLossData
Expand All @@ -2219,6 +2228,14 @@ class TuneResultDatapointValidationLossData(ApiBaseModel):
step: Optional[int] = None
value: float

@field_validator("epoch", mode="before")
@classmethod
def _validate_epoch(cls, value: Any):
result_value = int(value)
if result_value != float(value):
warnings.warn(f"The epoch was rounded down from {value} to {result_value}", stacklevel=4)
return result_value


class TuneResultFiles(ApiBaseModel):
created_at: Optional[AwareDatetime] = None
Expand Down
Loading