-
Notifications
You must be signed in to change notification settings - Fork 328
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
# 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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 {_}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}' | ||
|
@@ -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": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
inds = np.argsort(distances, axis=1)[:, -1:-topk - 1:-1] | ||
else: | ||
inds = np.argsort(distances, axis=1)[:, :topk] | ||
|
There was a problem hiding this comment.
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
.