Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Made Sampler and InferenceParameters threadsafe #292

Merged
merged 1 commit into from
Jun 2, 2023
Merged

Made Sampler and InferenceParameters threadsafe #292

merged 1 commit into from
Jun 2, 2023

Conversation

LLukas22
Copy link
Contributor

@LLukas22 LLukas22 commented Jun 2, 2023

No description provided.

Copy link
Contributor

@danforbes danforbes left a comment

Choose a reason for hiding this comment

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

Looks very simple and was informally approved by @philpax in Discord, so I feel safe merging.

@danforbes danforbes merged commit 2e93f87 into rustformers:main Jun 2, 2023
@@ -85,6 +85,11 @@ pub struct InferenceParameters {
/// sampler that offers a [Default](samplers::TopPTopK::default) implementation.
pub sampler: Arc<dyn Sampler>,
}

//Since Sampler implements Send and Sync, InferenceParameters should too.
unsafe impl Send for InferenceParameters {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

hol up is this necessary? won't these be inherited?

Copy link
Collaborator

Choose a reason for hiding this comment

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

(it's fine but I don't think it's needed?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PyO3 was complaining, so i had to wrap it in an Arc<>. With this i can just use it in a python objekt.

Copy link
Collaborator

Choose a reason for hiding this comment

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

weird, I think it should automatically infer Send + Sync for inference parameters as all the fields should be, too 🤔

It's totally fine as is, but can you try playing around with it and see if it still compiles without the unsafe impls?

@LLukas22 LLukas22 deleted the feat/threadsafe-sampler branch June 12, 2023 13:07
@hhamud hhamud mentioned this pull request Aug 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants