Skip to content
New issue

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

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

Already on GitHub? # to your account

Add type checker in converter for callable functions (optimizer, scheduler) #3968

Merged
Merged
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
14 changes: 12 additions & 2 deletions src/otx/tools/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,22 @@ def update_inference_batch_size(param_value: int) -> None:
config["data"]["test_subset"]["batch_size"] = param_value

def update_learning_rate(param_value: float) -> None:
config["model"]["init_args"]["optimizer"]["init_args"]["lr"] = param_value
optimizer = config["model"]["init_args"]["optimizer"]
if isinstance(optimizer, dict) and "init_args" in optimizer:
optimizer["init_args"]["lr"] = param_value
else:
warn("Warning: learning_rate is not updated", stacklevel=1)

def update_learning_rate_warmup_iters(param_value: int) -> None:
scheduler = config["model"]["init_args"]["scheduler"]
if scheduler["class_path"] == "otx.core.schedulers.LinearWarmupSchedulerCallable":
if (
isinstance(scheduler, dict)
and "class_path" in scheduler
and scheduler["class_path"] == "otx.core.schedulers.LinearWarmupSchedulerCallable"
):
scheduler["init_args"]["num_warmup_steps"] = param_value
else:
warn("Warning: learning_rate_warmup_iters is not updated", stacklevel=1)

def update_num_iters(param_value: int) -> None:
config["max_epochs"] = param_value
Expand Down
Loading