Skip to content

Commit

Permalink
Pull request update/240417
Browse files Browse the repository at this point in the history
1685a40 OS-7482. Fixed bug with removed list values in etcd
1a99bd4 OS-7425. Fixed etcd black and white lists values
a32ea69 OS-7463. Leaderboards improvements
  • Loading branch information
stanfra authored Apr 17, 2024
2 parents 4cb3343 + 1685a40 commit 82fdb2f
Show file tree
Hide file tree
Showing 12 changed files with 442 additions and 32 deletions.
11 changes: 9 additions & 2 deletions arcee/arcee_receiver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ class LeaderboardPatchIn(LeaderboardPostIn):
primary_metric: Optional[str] = None
group_by_hp: Optional[bool] = None

@model_validator(mode='after')
def set_metrics(self):
self.metrics = list(set(self.other_metrics))
if self.primary_metric:
self.metrics = list(set(self.metrics + [self.primary_metric]))
return self


class Leaderboard(LeaderboardPostIn):
id: str = id_
Expand All @@ -160,8 +167,8 @@ class Config:


class LeaderboardDatasetPatchIn(BaseModel):
dataset_ids: Optional[list]
name: Optional[str]
dataset_ids: Optional[list] = []
name: Optional[str] = None

@staticmethod
def remove_dup_ds_ids(kwargs):
Expand Down
64 changes: 64 additions & 0 deletions arcee/arcee_receiver/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ async def cluster_secret(self):

class Urls:
leaderboards = '/arcee/v2/tasks/{}/leaderboards'
leaderboard_datasets = '/arcee/v2/leaderboards/{}/leaderboard_datasets'
leaderboard_dataset = '/arcee/v2/leaderboard_datasets/{}'
tasks = '/arcee/v2/tasks'
task = '/arcee/v2/tasks/{}'
models = '/arcee/v2/models'
Expand Down Expand Up @@ -101,6 +103,68 @@ async def prepare_run(task_id, start, state, number, data):
return await DB_MOCK['run'].find_one({'_id': run['_id']})


async def prepare_leaderboard(primary_metric, task_id, other_metrics=None,
filters=None, group_by_hp=False,
grouping_tags=None):
if other_metrics is None:
other_metrics = []
if filters is None:
filters = []
if grouping_tags is None:
grouping_tags = []
lb = {
"_id": str(uuid.uuid4()),
"primary_metric": primary_metric,
"other_metrics": other_metrics,
"filters": filters,
"group_by_hp": group_by_hp,
"grouping_tags": grouping_tags,
"task_id": task_id,
"token": TOKEN1,
"created_at": int(datetime.now(tz=timezone.utc).timestamp()),
"deleted_at": 0
}
await DB_MOCK['leaderboard'].insert_one(lb)
return await DB_MOCK['leaderboard'].find_one({'_id': lb['_id']})


async def prepare_leaderboard_dataset(leaderboard_id, name=None,
dataset_ids=None):
if dataset_ids is None:
dataset_ids = []
leaderboard_dataset = {
"_id": str(uuid.uuid4()),
"leaderboard_id": leaderboard_id,
"name": name or 'test',
"dataset_ids": dataset_ids,
"token": TOKEN1,
"created_at": int(datetime.now(tz=timezone.utc).timestamp()),
"deleted_at": 0
}
await DB_MOCK['leaderboard_dataset'].insert_one(leaderboard_dataset)
return await DB_MOCK['leaderboard_dataset'].find_one(
{'_id': leaderboard_dataset['_id']})


async def prepare_dataset(name=None, description=None, labels=None, path=None,
training_set=None, validation_set=None):
if labels is None:
labels = []
dataset = {
"_id": str(uuid.uuid4()),
"name": name or 'test',
"description": description or 'test',
"labels": labels,
"path": path or 'test',
"training_set": training_set,
"validation_set": validation_set,
"created_at": int(datetime.now(tz=timezone.utc).timestamp()),
"deleted_at": 0
}
await DB_MOCK['dataset'].insert_one(dataset)
return await DB_MOCK['dataset'].find_one({'_id': dataset['_id']})


async def prepare_model(token=TOKEN1, key="key"):
model = {
"_id": str(uuid.uuid4()),
Expand Down
2 changes: 2 additions & 0 deletions arcee/arcee_receiver/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ async def clean_env():
await DB_MOCK['metric'].drop()
await DB_MOCK['task'].drop()
await DB_MOCK['leaderboard'].drop()
await DB_MOCK['leaderboard_dataset'].drop()
await DB_MOCK['run'].drop()
await DB_MOCK['model'].drop()
await DB_MOCK['model_version'].drop()
await DB_MOCK['log'].drop()
await DB_MOCK['platform'].drop()
await DB_MOCK['dataset'].drop()


@pytest.fixture(autouse=True)
Expand Down
29 changes: 29 additions & 0 deletions arcee/arcee_receiver/tests/test_leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,35 @@ async def test_patch_leaderboard(app):
assert response.json == lb


@pytest.mark.asyncio
async def test_patch_leaderboard_group_by_hp(app):
client = app.asgi_client
await prepare_token()
metrics = await prepare_metrics()
tasks = await prepare_tasks()
lb = {
"_id": str(uuid.uuid4()),
"primary_metric": metrics[0]['_id'],
"task_id": tasks[0]['_id'],
"other_metrics": [metrics[1]['_id']],
"filters": [{"id": metrics[1]['_id'], "min": 0, "max": 100}],
"group_by_hp": True,
"grouping_tags": [],
"deleted_at": 0,
"created_at": int(datetime.now(tz=timezone.utc).timestamp()),
"token": TOKEN1
}
await DB_MOCK['leaderboard'].insert_one(lb)
lb_update = {
"group_by_hp": False
}
_, response = await client.patch(Urls.leaderboards.format(tasks[0]['_id']),
headers={"x-api-key": TOKEN1},
data=json.dumps(lb_update))
assert response.status == 200
assert response.json['group_by_hp'] is False


@pytest.mark.asyncio
async def test_patch_invalid_params(app):
client = app.asgi_client
Expand Down
Loading

0 comments on commit 82fdb2f

Please sign in to comment.