Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Add Hyperparameter the GetGroups call with aggregate values #10175

Open
wants to merge 5 commits into
base: feature/row-grouping
Choose a base branch
from
Open
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: 16 additions & 0 deletions harness/determined/common/api/bindings.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 39 additions & 11 deletions master/internal/api_runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,8 @@ func (a *apiServer) GetRunGroups(ctx context.Context, req *apiv1.GetRunGroupsReq

resp := &apiv1.GetRunGroupsResponse{}
var groups []*runv1.RunGroup
query := db.Bun().NewSelect().
Model(&groups).
ModelTableExpr("runs AS r").
searchQuery := db.Bun().NewSelect().
TableExpr("runs AS r").
Apply(getRunsGroupsColumns)

var proj *projectv1.Project
Expand All @@ -1103,36 +1102,64 @@ func (a *apiServer) GetRunGroups(ctx context.Context, req *apiv1.GetRunGroupsReq
return nil, err
}

query = query.Where("r.project_id = ?", req.ProjectId)
searchQuery = searchQuery.Where("r.project_id = ?", req.ProjectId)
}
if query, err = experiment.AuthZProvider.Get().
FilterExperimentsQuery(ctx, *curUser, proj, query,
if searchQuery, err = experiment.AuthZProvider.Get().
FilterExperimentsQuery(ctx, *curUser, proj, searchQuery,
[]rbacv1.PermissionType{rbacv1.PermissionType_PERMISSION_TYPE_VIEW_EXPERIMENT_METADATA},
); err != nil {
return nil, err
}
if req.Filter != nil {
query, err = filterRunQuery(query, req.Filter)
searchQuery, err = filterRunQuery(searchQuery, req.Filter)
if err != nil {
return nil, err
}
}

if req.Sort != nil {
err = sortRuns(req.Sort, query, false)
err = sortRuns(req.Sort, searchQuery, false)
if err != nil {
return nil, err
}
} else {
query.OrderExpr("group_name ASC")
searchQuery.OrderExpr("group_name ASC")
}

groupName, err := runColumnNameToSQL(req.Group)
if err != nil {
return nil, err
}
query.Group(groupName)
query.ColumnExpr(fmt.Sprintf("%s AS group_name", groupName))
searchQuery.Group(groupName)
searchQuery.ColumnExpr(fmt.Sprintf("%s AS group_name", groupName))

query := db.Bun().NewSelect().
ColumnExpr("run_groups.group_name").
ColumnExpr("run_groups.start_time").
ColumnExpr("run_groups.end_time").
ColumnExpr("run_groups.checkpoint_size").
ColumnExpr("run_groups.checkpoint_count").
ColumnExpr("run_groups.searcher_metric_value").
ColumnExpr("run_groups.duration").
ColumnExpr("run_groups.user_ids").
ColumnExpr("run_groups.resource_pools").
ColumnExpr("run_groups.searcher_types").
ColumnExpr("run_groups.searcher_metrics").
ColumnExpr("run_groups.run_count").
ColumnExpr("array_to_json(run_groups.run_ids) as run_ids").
ColumnExpr(`(SELECT jsonb_concat_agg(jsonb_build_object(s.hparam,
jsonb_build_object(
'number_val', s.number_val,
'text_val', s.text_val,
'bool_val', s.bool_val)
)) FROM (
SELECT hparam, avg(number_val) as number_val,
json_agg(distinct coalesce(text_val, '')) as text_val,
bool_or(bool_val) as bool_val
FROM run_hparams rh WHERE rh.run_id = ANY (run_groups.run_ids)
GROUP BY rh.hparam) as s) as hyperparameters`).
Model(&groups).
ModelTableExpr("(?) as run_groups", searchQuery)
pagination, err := runPagedBunExperimentsQuery(ctx, query, int(req.Offset), int(req.Limit))
if err != nil {
return nil, err
Expand All @@ -1155,6 +1182,7 @@ func getRunsGroupsColumns(q *bun.SelectQuery) *bun.SelectQuery {
ColumnExpr("json_agg(distinct e.config->'searcher'->>'name') as searcher_types").
ColumnExpr("json_agg(distinct e.config->'searcher'->>'metric') as searcher_metrics").
ColumnExpr("COUNT(*) AS run_count").
ColumnExpr("array_agg(r.id) as run_ids").
Join("LEFT JOIN experiments AS e ON r.experiment_id=e.id").
Join("LEFT JOIN runs_metadata AS rm ON r.id=rm.run_id").
Join("LEFT JOIN users u ON e.owner_id = u.id").
Expand Down
48 changes: 47 additions & 1 deletion master/internal/api_runs_intg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,12 @@ func TestGetRunGroups(t *testing.T) {
Sort: ptrs.Ptr("state=asc"),
}

hyperparameters := map[string]any{"global_batch_size": 1, "test1": map[string]any{"test2": 1}}
hyperparameters := map[string]any{
"global_batch_size": 1,
"test1": map[string]any{"test2": 1},
"stringH": "abc",
"boolH": false,
}

exp := createTestExpWithProjectID(t, api, curUser, projectIDInt)

Expand Down Expand Up @@ -1839,4 +1844,45 @@ func TestGetRunGroups(t *testing.T) {
resp, err = api.GetRunGroups(ctx, req)
require.NoError(t, err)
require.Len(t, resp.Groups, 1)

// Add new task with different hyperperameter values
newHparams := map[string]any{
"global_batch_size": 9,
"test1": map[string]any{"test2": 8},
"stringH": "def",
"boolH": true,
}

exp3 := createTestExpWithProjectID(t, api, curUser, projectIDInt)

task = &model.Task{TaskType: model.TaskTypeTrial, TaskID: model.NewTaskID()}
require.NoError(t, db.AddTask(ctx, task))
require.NoError(t, db.AddTrial(ctx, &model.Trial{
State: model.PausedState,
ExperimentID: exp3.ID,
StartTime: time.Now(),
HParams: newHparams,
}, task.TaskID))

req = &apiv1.GetRunGroupsRequest{
ProjectId: &projectID,
Group: "state",
Sort: ptrs.Ptr("state=asc"),
}

resp, err = api.GetRunGroups(ctx, req)
require.NoError(t, err)
require.Len(t, resp.Groups, 2)
require.Equal(t, string(model.PausedState), resp.Groups[0].GroupName)
require.Equal(t, string(model.CanceledState), resp.Groups[1].GroupName)
require.InEpsilon(t, float64(5), resp.Groups[0].Hyperparameters.Fields["global_batch_size"].
GetStructValue().Fields["number_val"].GetNumberValue(), 0.00001)
require.InEpsilon(t, 4.5, resp.Groups[0].Hyperparameters.Fields["test1.test2"].
GetStructValue().Fields["number_val"].GetNumberValue(), 0.00001)
require.Equal(t, "abc", resp.Groups[0].Hyperparameters.Fields["stringH"].
GetStructValue().Fields["text_val"].GetListValue().Values[0].GetStringValue())
require.Equal(t, "def", resp.Groups[0].Hyperparameters.Fields["stringH"].
GetStructValue().Fields["text_val"].GetListValue().Values[1].GetStringValue())
require.True(t, resp.Groups[0].Hyperparameters.Fields["boolH"].
GetStructValue().Fields["bool_val"].GetBoolValue())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
create aggregate jsonb_concat_agg(jsonb)(
sfunc = jsonb_concat(jsonb, jsonb),
stype = jsonb
);
4 changes: 4 additions & 0 deletions performance/daist/daist/rest_api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def read_only_tasks(resources: Resources) -> LocustTasksWithMeta:
tasks.append(LocustGetTaskWithMeta(
f"/api/v1/projects/{resources.project_id}/columns",
test_name="get project columns"))

tasks.append(LocustGetTaskWithMeta(
f"/api/v1/runs/groups?projectId={resources.project_id}&group=state",
test_name="get groups"))

if resources.workspace_id is not None:
tasks.append(LocustGetTaskWithMeta(
Expand Down
62 changes: 44 additions & 18 deletions proto/pkg/runv1/run.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions proto/src/determined/run/v1/run.proto
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,8 @@ message RunGroup {
repeated string resource_pools = 11;
// The number of runs in the group.
int32 run_count = 12;
// The run ids of the runs that belong to the group
repeated int32 run_ids = 13;
// hyperparameters.
optional google.protobuf.Struct hyperparameters = 14;
}
12 changes: 12 additions & 0 deletions webui/react/src/services/api-ts-sdk/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading