Skip to content

Commit

Permalink
fix(tune): round fractional epoch in tune data points
Browse files Browse the repository at this point in the history
  • Loading branch information
jezekra1 committed Jul 2, 2024
1 parent 63d7c56 commit 5df2829
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
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
21 changes: 21 additions & 0 deletions scripts/types_generator/schema_aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ replace:
source_name: 'PromptTypeTmp'
force: true


# The following models are replaced by more specific schema from database:
'TextGenerationParameters': 'TextGenerationParametersFromDB'
'TextGenerationReturnOptions': 'TextGenerationReturnOptionsFromDB'
Expand All @@ -822,3 +823,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

0 comments on commit 5df2829

Please sign in to comment.