Skip to content
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

[V2 Pipeline] Middleware manager #1471

Merged
merged 21 commits into from
Jan 3, 2024
Merged

Conversation

horheynm
Copy link
Member

@horheynm horheynm commented Dec 13, 2023

Description

Adds ability to run middlewares for Pipeline and Operator callables

Problem

No existing way to just get the timings of each callable, add a generic manager for now, TimerManager in a separate pr

Solution

Create middleware manager and add a chain of callables to call middlewares before calling the callables

Design

Very similar to Starlette (Fastapi) middleware. Before calling the callables for Pipeline or Operator, add a "gadget" where the gadget logic is called before and after the callable.

One note is that Pipeline and Operator do not rely on the middleware. It doesnt know it exists. It is just a helper.

Usage

Check tests,

middleware = [MiddlewareSpec(ReducerMiddleware)]
middleware_manager = MiddlewareManager(middleware)
Pipeline(...,middleware_manager=middleware_manager)

Testing

Checks the functionality of middleware and middleware managers work as expected

@horheynm horheynm changed the title middleware manager with tests [V2 Pipeline] Middleware manager Dec 13, 2023
@horheynm horheynm mentioned this pull request Dec 13, 2023
src/deepsparse/middlewares/middleware.py Show resolved Hide resolved
src/deepsparse/middlewares/middleware.py Show resolved Hide resolved
src/deepsparse/middlewares/middleware.py Show resolved Hide resolved
src/deepsparse/operators/operator.py Outdated Show resolved Hide resolved
src/deepsparse/pipeline.py Outdated Show resolved Hide resolved
bfineran
bfineran previously approved these changes Dec 13, 2023
src/deepsparse/pipeline.py Outdated Show resolved Hide resolved
src/deepsparse/pipeline.py Outdated Show resolved Hide resolved
dsikka
dsikka previously requested changes Dec 14, 2023
src/deepsparse/pipeline.py Show resolved Hide resolved
src/deepsparse/pipeline.py Show resolved Hide resolved
src/deepsparse/pipeline.py Outdated Show resolved Hide resolved
src/deepsparse/pipeline.py Outdated Show resolved Hide resolved
Copy link
Contributor

@bfineran bfineran left a comment

Choose a reason for hiding this comment

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

LGTM pending unresolved comment

src/deepsparse/pipeline.py Outdated Show resolved Hide resolved
@horheynm horheynm force-pushed the v2/middleware-manager-after-v2-merge branch from c7fe1a7 to f311e15 Compare December 19, 2023 15:22
bfineran
bfineran previously approved these changes Dec 19, 2023
Copy link
Contributor

@bfineran bfineran left a comment

Choose a reason for hiding this comment

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

Approved - there are comments that need to be deleted however

@bfineran
Copy link
Contributor

also - as discussed we need to cut down on the number of times we instantiate the actual middleware callable classes

Copy link
Contributor

@dsikka dsikka left a comment

Choose a reason for hiding this comment

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

same as other PRs, could we merge in pipeline.py and make sure everything works as expected?

src/deepsparse/middlewares/middleware.py Outdated Show resolved Hide resolved
src/deepsparse/middlewares/middleware.py Outdated Show resolved Hide resolved
src/deepsparse/middlewares/middleware.py Outdated Show resolved Hide resolved
src/deepsparse/middlewares/middleware.py Show resolved Hide resolved
src/deepsparse/middlewares/middleware.py Show resolved Hide resolved
src/deepsparse/middlewares/middleware.py Show resolved Hide resolved
src/deepsparse/middlewares/middleware.py Outdated Show resolved Hide resolved
src/deepsparse/pipeline.py Show resolved Hide resolved
src/deepsparse/pipeline.py Show resolved Hide resolved
tests/deepsparse/middlewares/utils.py Outdated Show resolved Hide resolved
bfineran
bfineran previously approved these changes Dec 26, 2023
@bfineran bfineran merged commit dbef7d3 into main Jan 3, 2024
13 checks passed
@bfineran bfineran deleted the v2/middleware-manager-after-v2-merge branch January 3, 2024 19:32
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.

4 participants