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

refactor: remove model-associated inference params #272

Merged
merged 3 commits into from
May 24, 2023

Conversation

philpax
Copy link
Collaborator

@philpax philpax commented May 23, 2023

While well-intentioned, the presence of the parameters on the model suggests to users that these are parameters optimised for the model.

Unfortunately, that's not quite what they are in practice - they're the parameters passed into the load function, which the vast majority of users will call with Default::default.

I've attacked this with two changes:

  • I've removed the Default implementation for InferenceParameters and moved it to a reasonable_default method, to make it clearer that this is something that you as a user will need to think about and can't idly hide in a Default::default call somewhere
  • I've removed the model-attached parameters. In practice, this doesn't appear to have significantly complicated the examples, so I'm not too concerned about the usability hit.

Please let me know if this is the right call to make.

@philpax philpax requested a review from danforbes May 23, 2023 20:34
@philpax philpax marked this pull request as ready for review May 23, 2023 20:35
Comment on lines 67 to 76
impl InferenceParameters {
/// Returns a reasonable default for the parameters.
///
/// Note that these parameters are not necessarily optimal for all models, and that
/// you may want to tweak them for your use case.
///
/// This is intentionally not a `Default` implementation. The values specified here may change
/// in the future, and we want to make sure that users are aware of this and do not accidentally
/// rely on the values.
pub const fn reasonable_default() -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels unnecessary to me. Is there anything that states that a default implementation should be expected to be optimal in all circumstances? It also seems like semantic versioning should be used to take care of breaking changes...choosing a different name for something that will effectively still be used the same way isn't going to help anything. This isn't a hill I'm going to die on, but I just have a strong preference for the use of idiomatic traits.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see where you're coming from and I'm not super-sure about this myself, but I wanted to deliberately disable the use of Default so that the user can't just smash Default::default in without thinking about it at all.

But perhaps you're right, and there's not really that much distinction in practice. I'll think about it...

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO the "correct" way to approach it would be to add documentation to InferenceParameter, InferenceRequest and infer that specifies that it's highly discouraged to use default InferenceParameters in production/performance-sensitive situations 🤷🏻

@philpax philpax force-pushed the remove-model-inference-params branch from e651744 to b4a4b16 Compare May 24, 2023 20:58
@philpax philpax merged commit 23da0b6 into main May 24, 2023
@philpax philpax deleted the remove-model-inference-params branch May 24, 2023 21:03
@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.

2 participants