Skip to content

Move featurizer batch part to serving computation - #243

Merged
jonatanklosko merged 2 commits into
mainfrom
jk-split-featurizer
Sep 13, 2023
Merged

Move featurizer batch part to serving computation#243
jonatanklosko merged 2 commits into
mainfrom
jk-split-featurizer

Conversation

@jonatanklosko

Copy link
Copy Markdown
Member

馃悎

If the featurizer does not define batch processing, the input is
returned as is.
"""
@callback apply(t(), input :: any(), defn_options :: keyword()) :: any()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't deprecate, because it's very unlikely that someone implements a featurizer outside bumblebee.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Beautiful. If you want to keep backwards compatibility, you could keep it as a apply and introduce apply_batch.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would rather check for it as fallback, I just don't think it's worth in this case.

As for naming, I didn't go with apply_batch because then it seems as if apply_batch were batched version of apply. I'm not sure the current naming is perfect either, but the best I come up with :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your call, just mentioning for completeness.

Comment thread lib/bumblebee/featurizer.ex Outdated
@callback apply(t(), input :: any(), defn_options :: keyword()) :: any()
@spec process_batch(t(), Nx.t() | Nx.Container.t()) :: Nx.t() | Nx.Container.t()
def process_batch(%module{} = featurizer, batch) do
if function_exported?(module, :process_batch, 2) do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Keep in mind this will only work if module is already loaded (which will be the case if you have called a previous function in module).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah right, will add ensure loaded!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

FWIW it should be loaded, because we would call configure/2 in the module when loading the featurizer. But I still like checking since it's one less thing to think about :)

@josevalim josevalim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great!

@jonatanklosko
jonatanklosko merged commit 2af8cf3 into main Sep 13, 2023
@jonatanklosko
jonatanklosko deleted the jk-split-featurizer branch September 13, 2023 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants