Skip to content

Better pipeline type hints ✨ #38049

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

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

qubvel
Copy link
Member

@qubvel qubvel commented May 9, 2025

What does this PR do?

With the power of @overload this PR adds several features to make our pipelines more IDE-friendly (and as a bonus more Curosor, Copilot and autocompletion friendly).

1. Correctly resolve pipeline type in case task is specified for pipeline function

pipe_type

As a result, we have pipeline-specific docs and method signatures fetched by IDE

Screenshot 2025-05-09 at 17 09 12

2. Resolve ambiguities regarding the input and output types for pipelines

For example,

  • if we provide one image, we will get a dict output
  • if we provide multiple images we will get list of dict outputs

output_type

The part of the code is autogenerated and added to the pipelines/__init__.py + added CI check / fix

@qubvel qubvel marked this pull request as ready for review May 9, 2025 16:49
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@qubvel
Copy link
Member Author

qubvel commented May 9, 2025

The code is a bit bloated, but since pipeline acts more like an API (and is already somewhat bloated 😅), I think it's worth optimizing the user experience.
@Rocketknight1 @Cyrilvallez curious to hear your thoughts!

@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import subprocess
from typing import Union
from typing import Any, Dict, List, Union
Copy link
Contributor

Choose a reason for hiding this comment

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

From readme I see transformers supports py 3.9+. According to py doc, there is no need to use typing.Dict and List.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Will replace 🤗

@qubvel qubvel requested a review from Rocketknight1 May 12, 2025 14:55
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.

3 participants