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
Signed-off-by: Radek Ježek <pc.jezek@gmail.com>
  • Loading branch information
jezekra1 committed Jul 2, 2024
1 parent 63d7c56 commit b635d9f
Show file tree
Hide file tree
Showing 3 changed files with 39 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
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

0 comments on commit b635d9f

Please sign in to comment.