-
Notifications
You must be signed in to change notification settings - Fork 644
perf(search): share a thread-local RNG for HNSW and drop seed (#2398) #3562
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
Open
advisedy
wants to merge
8
commits into
apache:unstable
Choose a base branch
from
advisedy:#2398
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+11
−13
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3e3b1aa
perf(search): lazily initialize HNSW random generator
advisedy 5cfd455
fix(search): only call random_device when seed is not set
advisedy 6c3ad7d
Merge branch 'unstable' into #2398
advisedy d53751b
Merge branch 'unstable' into #2398
jihuayu 3b7a688
perf(search): use a static thread-local RNG for HNSW indexes
advisedy ff60ae2
perf(search): drop seed, make the RNG a class member
advisedy 859bbaf
Merge branch 'unstable' into #2398
advisedy 03c941f
fix(search): mark RandomizeLayer and InsertVectorEntry as const
advisedy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
seedis very weird here.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.
You're right — the semantics of
seedis indeed weird here. Since thegenerator is now shared, only the first instance's seed would take
effect, which is misleading.
I see two possible directions:
Share the generator only among indexes with the same seed, and let
indexes with different seeds keep their own. I haven't fully figured
out the implementation yet, but maybe a
static thread_localmapcould work? It seems like that might be doable.
Drop
seedentirely, seed the generator withstd::random_device,and make it a class-level
static thread_local std::mt19937member(no longer a function-local static), so its initialization no longer
depends on any specific instance.
I'd like to know which direction you think we should take. If you
prefer option 1, I'll think about how to implement it in detail. If
it's option 2, I'll go ahead and do it now.
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.
Could you stop copy-pasting to me what your agent replies to you? You can do your own decision. I have enough token that I don't need an agent proxy.
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.
Sorry, my english is not good, so I tell AI what I was thinking and let it translate. But The decision is mine. please.
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.
Here is my origin words: 确实感觉seed有点奇怪在这里,但是generator得根据seed去生成出来,不如说这里seed,generator,和我们期望共享的逻辑有点混乱,我的理解有两种思路,第一种思路就是我们考虑对于seed一样的进行共享,不一样的就是各自持有,这种方法用static + thread_local + map 应该能实现出来? 但我感觉有点麻烦。第二种思路就是或许可以考虑直接把seed删掉,使用std::random_device,这样的话,static thread_local std::mt19937 generator; 放到类里面,不再是局部了,这样初始化也不会依赖某个实例。 想知道一下,你觉得我们应该怎么做会比较好呢?如果你想要第一种的思路,我再去思考具体该怎么实现会比较好。如果是第二种的话,我可以现在就去实现出来代码。
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.
I’m very sorry that I relied too much on AI when replying, but my genuine intention was to contribute. I’m truly sorry.
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.
seedhere.