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

fix: put HFTokenStreamingHandler in a lazy_import block #7403

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

anakin87
Copy link
Member

Related Issues

Several core-integrations tests with Haytstack main are failing after #7377
See for example https://github.com/deepset-ai/haystack-core-integrations/actions/runs/8383450235/job/22959180165

This happens because HFTokenStreamingHandler import in HFLocalGenerator is not inside a lazy_import block,
even if the class needs transformers

Proposed Changes:

put HFTokenStreamingHandler in a lazy_import block

How did you test it?

  • Locally rerun the failed core-integrations tests with this change
  • CI

Checklist

@anakin87 anakin87 added the ignore-for-release-notes PRs with this flag won't be included in the release notes. label Mar 22, 2024
@anakin87 anakin87 requested a review from a team as a code owner March 22, 2024 06:52
@anakin87 anakin87 requested review from silvanocerza and removed request for a team March 22, 2024 06:52
@github-actions github-actions bot added the 2.x Related to Haystack v2.0 label Mar 22, 2024
@@ -222,8 +222,7 @@ def check_generation_params(kwargs: Optional[Dict[str, Any]], additional_accepte
with LazyImport(message="Run 'pip install transformers[torch]'") as torch_and_transformers_import:
from transformers import PreTrainedTokenizer, PreTrainedTokenizerFast, StoppingCriteria, TextStreamer

transformers_import.check()
torch_import.check()
torch_and_transformers_import.check()
Copy link
Member Author

Choose a reason for hiding this comment

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

unrelated

@coveralls
Copy link
Collaborator

coveralls commented Mar 22, 2024

Pull Request Test Coverage Report for Build 8386643773

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 10 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.001%) to 89.279%

Files with Coverage Reduction New Missed Lines %
utils/hf.py 4 77.78%
components/generators/hugging_face_local.py 6 91.89%
Totals Coverage Status
Change from base Build 8376985254: -0.001%
Covered Lines: 5421
Relevant Lines: 6072

💛 - Coveralls

@anakin87 anakin87 requested a review from masci March 22, 2024 08:06
@vblagoje vblagoje self-requested a review March 22, 2024 08:36
@vblagoje
Copy link
Member

Yes, this is on me - apologies.

Copy link
Member

@vblagoje vblagoje left a comment

Choose a reason for hiding this comment

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

🙏 @anakin87

@anakin87 anakin87 merged commit d594445 into main Mar 22, 2024
20 checks passed
@anakin87 anakin87 deleted the fix-hf-lazy-import branch March 22, 2024 08:43
@lambda-science
Copy link
Contributor

I still have a small issue regarding this HFTokenStreamingHandler

  File "/code/haystack_api/pipeline/custom_pipelines.py", line 27, in <module>
2024-03-22T13:27:51.948291417Z     from haystack.components.generators.utils import print_streaming_chunk
2024-03-22T13:27:51.948294052Z   File "/usr/local/lib/python3.11/site-packages/haystack/components/generators/__init__.py", line 5, in <module>
2024-03-22T13:27:51.948297138Z     from haystack.components.generators.hugging_face_local import HuggingFaceLocalGenerator
2024-03-22T13:27:51.948301586Z   File "/usr/local/lib/python3.11/site-packages/haystack/components/generators/hugging_face_local.py", line 13, in <module>
2024-03-22T13:27:51.948308570Z     from haystack.utils.hf import deserialize_hf_model_kwargs, serialize_hf_model_kwargs
2024-03-22T13:27:51.948311495Z   File "/usr/local/lib/python3.11/site-packages/haystack/utils/hf.py", line 227, in <module>
2024-03-22T13:27:51.948314561Z     class StopWordsCriteria(StoppingCriteria):
2024-03-22T13:27:51.948324500Z   File "/usr/local/lib/python3.11/site-packages/haystack/utils/hf.py", line 243, in StopWordsCriteria
2024-03-22T13:27:51.948327546Z     device: Union[str, torch.device] = "cpu",
2024-03-22T13:27:51.948330792Z                        ^^^^^
2024-03-22T13:27:51.948333477Z NameError: name 'torch' is not defined

I don't use Huggingface at all so torch is not installed.

@silvanocerza silvanocerza added this to the 2.0.1 milestone Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Related to Haystack v2.0 ignore-for-release-notes PRs with this flag won't be included in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants