Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

[Pipeline Refactor] Migration#1460

Merged
dsikka merged 20 commits into
mainfrom
update_pathways
Dec 11, 2023
Merged

[Pipeline Refactor] Migration#1460
dsikka merged 20 commits into
mainfrom
update_pathways

Conversation

@dsikka

@dsikka dsikka commented Dec 6, 2023

Copy link
Copy Markdown
Contributor

Summary

  • Branch to update pathways such that the new text generation pipeline can be used
  • All new pipeline components and updated pipelines (text_generation, image_classification) were moved from the v2 pathway and are now the default pipelines that will be used
  • The old files have been moved to a legacy folder under src. Old text_generation and image_classification folders were also moved to legacy subfolders in their respective modules
  • To make it easier, text_generation schemas were moved to a separate folder under transformers/schemas making it easy for both the new and old pipelines to pull them in

Testing

  1. You can load the new pipelines using the normal Pipeline.create(...) method.
  2. If the pipeline has not been registered using the new registry/migrated to use the new framework, you can use Pipeline.create(...) as well. This will use the legacy pipeline class under the hood.
  3. To use the legacy pipeline (old text generation and old image classification) which have already been migrated, use have to use the legacy Pipeline under legacy/pipeline.py

All 3 examples are shown below.

Example:

Run the new text generation pipeline (with continuous batching, if that's what your heart desires):

from deepsparse import Pipeline
from deepsparse.transformers.schemas.text_generation_schemas import TextGenerationInput

pipeline = Pipeline.create(
    task="text_generation",
    model_path=model_path,
    engine_type="deepsparse",
    internal_kv_cache=False,
    continuous_batch_sizes=[2, 4]
)

prompts = [["Hello there!", "The sun shined bright", "The dog barked"]]
for i in range(len(prompts)):
    input_value = TextGenerationInput(
        prompt=prompts[i],
        generation_kwargs={
            "num_return_sequences": 4,
            "max_new_tokens": 20,
            "do_sample": True,
        },
    )
    output = pipeline(input_value)
    for i in output.generations:
        print(i)
        print("\n")

Run the old text_generation pipeline:

from deepsparse.legacy.pipeline import Pipeline
from deepsparse.transformers.schemas.text_generation_schemas import TextGenerationInput

model_path = "hf:neuralmagic/mpt-7b-chat-pruned50-quant"
pipeline = Pipeline.create(
    task="text_generation",
    model_path=model_path,
    engine_type="deepsparse",
    internal_kv_cache=True,
)

prompts = [["Hello there!", "The sun shined bright", "The dog barked"]]
input_value = TextGenerationInput(
    prompt=prompts[0],
    generation_kwargs={
        "num_return_sequences": 4,
        "max_new_tokens": 20,
        "do_sample": True,
    },
)

output = pipeline(input_value)
for i in output.generations:
    print(i)
    print("\n")

Run any pipeline that has not yet been migrated to use the new Pipeline class/framework

from deepsparse import Pipeline

sa_pipeline = Pipeline.create(
    task="sentiment-analysis",
    model_path="zoo:bert-large-sst2_wikipedia_bookcorpus-pruned90_quantized"
)

inference = sa_pipeline("I love it!")

Next Steps

  • Some of the tests needs to be updated to reflect the new pipeline changes (example: test_pipeline.py and test_dynamic_import.py). Right now they are testing the legacy pipeline.
  • To reflect then new text generation pipeline, test_text_generation.py needs to be updated. It is currently testing the legacy pipeline.
  • Update PIpeline.to_config/Pipeline.from_config such that new pipelines can be loaded in the server. Right now, only old pipelines can run on the server

@dbogunowicz dbogunowicz 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.

Few general inquires to @dsikka / @bfineran

  1. How in the future will the full "retirement" of V1 look like?
  2. I understand that once this PR lands, we stop any development of legacy code
  3. There are still two functionalities for V2 pipelines that need to land from my side: non-KV cache pipeline (ready for review) and streaming (WiP). Also there are small differences between V1 and V2 text generation pipeline (e.g. #1446). When do we want to get those in ASAP, to assert that V1 and V2 are identical?

Comment thread src/deepsparse/image_classification/validation_script.py
Comment thread src/deepsparse/operators/operator.py
Comment thread tests/deepsparse/pipelines/test_clip.py
Comment thread tests/deepsparse/transformers/pipelines/test_text_generation.py Outdated
@dsikka dsikka requested a review from dbogunowicz December 7, 2023 16:42
dbogunowicz
dbogunowicz previously approved these changes Dec 8, 2023
Comment thread tests/deepsparse/evaluation/test_utils.py
@dsikka dsikka requested a review from dbogunowicz December 8, 2023 15:47
bfineran
bfineran previously approved these changes Dec 8, 2023

@bfineran bfineran 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.

LGTM pending tests passing and confirmation that user facing scripts run as expected - examples look great

Comment thread src/deepsparse/transformers/pipelines/code_generation.py Outdated
@dsikka dsikka merged commit 23096ef into main Dec 11, 2023
@dsikka dsikka deleted the update_pathways branch December 11, 2023 15:16
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