Skip to content
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
16 changes: 15 additions & 1 deletion aixplain/modules/finetune/hyperparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@
from dataclasses_json import dataclass_json


class SchedulerType:
LINEAR = "linear"
COSINE = "cosine"
COSINE_WITH_RESTARTS = "cosine_with_restarts"
POLYNOMIAL = "polynomial"
CONSTANT = "constant"
CONSTANT_WITH_WARMUP = "constant_with_warmup"
INVERSE_SQRT = "inverse_sqrt"
REDUCE_ON_PLATEAU = "reduce_lr_on_plateau"


@dataclass_json
@dataclass
class Hyperparameters(object):
epochs: int = 4
train_batch_size: int = 4
eval_batch_size: int = 4
learning_rate: float = 2e-5
warmup_steps: int = 500
generation_max_length: int = 225
tokenizer_batch_size: int = 256
gradient_checkpointing: bool = False
gradient_accumulation_steps: int = 1
max_seq_length: int = 4096
warmup_ratio: float = 0.0
warmup_steps: int = 0
early_stopping_patience: int = 1
lr_scheduler_type: SchedulerType = SchedulerType.LINEAR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does @dataclass_json converts the enumerator to string automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, by running the following line:

finetune = FinetuneFactory.create(str(uuid.uuid4()), dataset_list, model, hyperparameters=Hyperparameters(lr_scheduler_type=SchedulerType.CONSTANT))

We get the following request body:

{
  "datasets": [
    {
      "datasetId": "65293795abed4d551b86baac",
      "trainPercentage": 100,
      "devPercentage": 0
    }
  ],
  "sourceModelId": "64e615671567f848804985e1",
  "parameters": {
    "hyperparameters": {
      "epochs": 4,
      "train_batch_size": 4,
      "eval_batch_size": 4,
      "learning_rate": 2e-05,
      "generation_max_length": 225,
      "tokenizer_batch_size": 256,
      "gradient_checkpointing": false,
      "gradient_accumulation_steps": 1,
      "max_seq_length": 4096,
      "warmup_ratio": 0.0,
      "warmup_steps": 0,
      "early_stopping_patience": 1,
      "lr_scheduler_type": "constant"
    }
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should you include these parameters in the functional test?

3 changes: 2 additions & 1 deletion tests/functional/finetune/finetune_functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def validate_prompt_input_map(request):


def test_end2end_text_generation(run_input_map):
model = ModelFactory.list(query=run_input_map["model_name"], is_finetunable=True)["results"][0]
model = ModelFactory.get(run_input_map["model_id"])
dataset_list = [DatasetFactory.list(query=run_input_map["dataset_name"])["results"][0]]
train_percentage, dev_percentage = 100, 0
if run_input_map["required_dev"]:
Expand All @@ -74,6 +74,7 @@ def test_end2end_text_generation(run_input_map):
while status != "onboarded" and (end - start) < TIMEOUT:
status = finetune_model.check_finetune_status()
assert status != "failed"
time.sleep(5)
end = time.time()
assert finetune_model.check_finetune_status() == "onboarded"
result = finetune_model.run(run_input_map["inference_data"])
Expand Down