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

refactor: Avoid using OrderedDict in the manager API and client SDK (#2842) #2843

Merged
merged 2 commits into from
Sep 18, 2024
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
1 change: 1 addition & 0 deletions changes/2842.enhance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid using `collections.OrderedDict` when not necessary in the manager API and client SDK
6 changes: 3 additions & 3 deletions src/ai/backend/client/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json as modjson
import logging
import sys
from collections import OrderedDict, namedtuple
from collections import namedtuple
from datetime import datetime
from decimal import Decimal
from pathlib import Path
Expand Down Expand Up @@ -412,7 +412,7 @@ async def text(self) -> str:
return await self._raw_response.text()

async def json(self, *, loads=modjson.loads) -> Any:
loads = functools.partial(loads, object_pairs_hook=OrderedDict)
loads = functools.partial(loads)
return await self._raw_response.json(loads=loads)

async def read(self, n: int = -1) -> bytes:
Expand All @@ -433,7 +433,7 @@ def text(self) -> str:
)

def json(self, *, loads=modjson.loads) -> Any:
loads = functools.partial(loads, object_pairs_hook=OrderedDict)
loads = functools.partial(loads)
sync_session = cast(SyncSession, self._session)
return sync_session.worker_thread.execute(
self._raw_response.json(loads=loads),
Expand Down
18 changes: 8 additions & 10 deletions src/ai/backend/manager/models/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import asyncio
import collections
import enum
import functools
import logging
Expand All @@ -20,7 +19,6 @@
Callable,
ClassVar,
Coroutine,
Dict,
Generic,
List,
NamedTuple,
Expand Down Expand Up @@ -806,8 +804,8 @@ async def batch_result(
"""
A batched query adaptor for (key -> item) resolving patterns.
"""
objs_per_key: Dict[_Key, Optional[_GenericSQLBasedGQLObject]]
objs_per_key = collections.OrderedDict()
objs_per_key: dict[_Key, Optional[_GenericSQLBasedGQLObject]]
objs_per_key = dict()
for key in key_list:
objs_per_key[key] = None
if isinstance(db_conn, SASession):
Expand All @@ -830,8 +828,8 @@ async def batch_multiresult(
"""
A batched query adaptor for (key -> [item]) resolving patterns.
"""
objs_per_key: Dict[_Key, List[_GenericSQLBasedGQLObject]]
objs_per_key = collections.OrderedDict()
objs_per_key: dict[_Key, list[_GenericSQLBasedGQLObject]]
objs_per_key = dict()
for key in key_list:
objs_per_key[key] = list()
if isinstance(db_conn, SASession):
Expand All @@ -857,8 +855,8 @@ async def batch_result_in_session(
A batched query adaptor for (key -> item) resolving patterns.
stream the result in async session.
"""
objs_per_key: Dict[_Key, Optional[_GenericSQLBasedGQLObject]]
objs_per_key = collections.OrderedDict()
objs_per_key: dict[_Key, Optional[_GenericSQLBasedGQLObject]]
objs_per_key = dict()
for key in key_list:
objs_per_key[key] = None
async for row in await db_sess.stream(query):
Expand All @@ -878,8 +876,8 @@ async def batch_multiresult_in_session(
A batched query adaptor for (key -> [item]) resolving patterns.
stream the result in async session.
"""
objs_per_key: Dict[_Key, List[_GenericSQLBasedGQLObject]]
objs_per_key = collections.OrderedDict()
objs_per_key: dict[_Key, list[_GenericSQLBasedGQLObject]]
objs_per_key = dict()
for key in key_list:
objs_per_key[key] = list()
async for row in await db_sess.stream(query):
Expand Down
Loading