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

add retry for download index & support MipsSquaredEuclidean #2134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 25 additions & 11 deletions mars/learn/proxima/simple_index/searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,30 @@ def _execute_download(cls, ctx, op: "ProximaSearcher"):
exist_state = False
if not os.path.exists(local_path.rsplit("/", 1)[0]):
os.mkdir(local_path.rsplit("/", 1)[0])
with open(local_path, 'wb') as out_f:
with fs.open(index_path, 'rb') as in_f:
# 32M
chunk_bytes = 32 * 1024 ** 2
while True:
data = in_f.read(chunk_bytes)
if data:
out_f.write(data)
else:
break

def read_index():
with open(local_path, 'wb') as out_f:
with fs.open(index_path, 'rb') as in_f:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with-block can hold multiple contexts, such as with func1() as v1, func2() as v2.

# 32M
chunk_bytes = 32 * 1024 ** 2
while True:
data = in_f.read(chunk_bytes)
if data:
out_f.write(data)
else:
break

# retry 3 times
for _ in range(3):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a variable name instead of _

try:
read_index()
logger.warning(f"read success")
break
except: # noqa: E722 # nosec # pylint: disable=bare-except
logger.warning(f"read index file faild for times {_}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failed for {n} times

os.remove(local_path)
logger.warning(f"remove {local_path} success")
continue

logger.warning(f'ReadingFromVolume({op.key}), index path: {index_path}, '
f'local_path {local_path}'
Expand Down Expand Up @@ -406,7 +420,7 @@ def _execute_agg(cls, ctx, op: "ProximaSearcher"):
topk = op.topk

# calculate topk on rows
if op.distance_metric == "InnerProduct":
if op.distance_metric == "InnerProduct" or op.distance_metric == "MipsSquaredEuclidean":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use op.distance_metric in ('InnerProduct', 'MipsSquaredEuclidean')?

inds = np.argsort(distances, axis=1)[:, -1:-topk - 1:-1]
else:
inds = np.argsort(distances, axis=1)[:, :topk]
Expand Down