Unanswered
Hello, I'Ve Set Up An Hpo Where I Upload Child Task Artifacts To The Optimizer Task. However, The Last Child Task Is Not Logged In The Optimizer In The Ui, Even Though The Task Is Running Correctly. (I Should Have Four Tasks)
Do You Know If I Am Missing
Hello, I've set up an HPO where I upload child task artifacts to the optimizer task. However, the last child task is not logged in the optimizer in the UI, even though the task is running correctly. (I should have four tasks)
Do you know if i am missing something? Thanks!
import time
from clearml.automation import UniformParameterRange, HyperParameterOptimizer, DiscreteParameterRange
from clearml.automation.optimization import GridSearch
from clearml import Task
import math
import pandas as pd
import os
parent_task = Task.init(
project_name='Test_parameter_optimization',
task_name='Automatic Hyper-Parameter Optimization',
task_type=Task.TaskTypes.optimizer,
reuse_last_task_id=False
)
temp_dir = "temp_child_artifacts"
os.makedirs(temp_dir, exist_ok=True)
# Define the hyperparameter ranges
hyper_parameters = [
UniformParameterRange('Args/elevation_noise', min_value=0, max_value=1, step_size=1),
UniformParameterRange('Args/speed_noise', min_value=0, max_value=1, step_size=1),
]
# Define the optimizer
optimizer = HyperParameterOptimizer(
base_task_id="71f5ebad33724d9382329bd48eff594f", # Replace with your actual template task ID
hyper_parameters=hyper_parameters,
optimizer_class=GridSearch,
objective_metric_title="DummyMetric", # Placeholder title
objective_metric_series="DummySeries", # Placeholder series
objective_metric_goal="min", # Placeholder goal (min/max)
)
def job_complete_callback(
job_id, # type: str
objective_value, # type: float
objective_iteration, # type: int
job_parameters, # type: dict
top_performance_job_id # type: str
):
print(f"Job completed: {job_id}")
print(f"Job parameters: {job_parameters}")
# Retrieve the completed child task
child_task = Task.get_task(task_id=job_id)
elevation_noise = job_parameters.get('Args/elevation_noise', 'unknown')
print(f"elevation_noise: {elevation_noise}")
# Fetch artifacts from the child task
artifacts = child_task.artifacts
for artifact_name, artifact in artifacts.items():
# Download the artifact locally
artifact_obj = artifact.get()
# Upload the artifact to the parent task
parent_task.upload_artifact(name=f"{job_id}_{artifact_name}", artifact_object=artifact_obj)
print(f"Added artifact '{artifact_name}' from Task {job_id} to the parent task.")
optimizer.set_report_period(0.5)
optimizer.start(job_complete_callback=job_complete_callback)
optimizer.wait()
print("Hyper-parameter optimization complete")
168 Views
0
Answers
one month ago
one month ago
Tags