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

Model: Device-id and data-parallel inference in CLI and Torch #452

Merged
merged 5 commits into from
Nov 11, 2024

Conversation

michaelfeil
Copy link
Owner

Description

Please provide a clear and concise description of the changes in this PR.

Related Issue

If applicable, link the issue this PR addresses.

Types of Change

  • Bug fix
  • [ x] New feature
  • Documentation update

Checklist

  • I have read the CONTRIBUTING guidelines.
  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My changes generate no new warnings.
  • I have updated the documentation accordingly.

Additional Notes

Add any other context about the PR here.

License

By submitting this PR, I confirm that my contribution is made under the terms of the MIT license.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Based on my analysis of the pull request, here is a concise summary of the key changes:

Added device-id and data-parallel inference capabilities to enable running models across multiple GPUs/devices:

  • Added new --device-id CLI option that accepts comma-separated device IDs (e.g. "0,1") for model placement across multiple GPUs/devices
  • Introduced LoadingStrategy class to manage device mapping, dtype configuration, and quantization settings across different hardware
  • Modified BatchHandler to support multiple model replicas running in parallel across specified devices
  • Updated test suite with retry logic and adjusted tolerance parameters to handle numerical differences from parallel processing
  • Added proper error handling for device validation and unavailable hardware configurations

The changes enable better scaling and performance through parallel inference while maintaining the existing API interface.

23 file(s) reviewed, 32 comment(s)
Edit PR Review Bot Settings | Greptile

│ --device-id TEXT device id defines the model │
│ placement. e.g. `0,1` will │
│ place the model on │
│ MPS/CUDA/GPU 0 and 1 each │
Copy link
Contributor

Choose a reason for hiding this comment

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

style: The phrase 'each' at the end of this line is ambiguous - does it mean the model is replicated on each device or split across devices?

libs/infinity_emb/infinity_emb/args.py Show resolved Hide resolved
Comment on lines 132 to 134
def update_loading_stategy(self):
"""Assign a device id to the EngineArgs object."""
from infinity_emb.inference import loading_strategy # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: update_loading_stategy() has a typo in its name (should be 'strategy')

Comment on lines 124 to 127
if self._loading_strategy is None:
self.update_loading_stategy()
elif isinstance(self._loading_strategy, dict):
object.__setattr__(self, "_loading_strategy", LoadingStrategy(**self._loading_strategy))
Copy link
Contributor

Choose a reason for hiding this comment

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

style: loading strategy initialization should happen before pydantic validation to ensure the complete object is validated

@@ -61,6 +67,8 @@ class EngineArgs:
embedding_dtype: EmbeddingDtype = EmbeddingDtype[MANAGER.embedding_dtype[0]]
served_model_name: str = MANAGER.served_model_name[0]

_loading_strategy: Optional[LoadingStrategy] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

style: _loading_strategy should be documented with a type hint comment explaining its purpose and structure

@codecov-commenter
Copy link

codecov-commenter commented Nov 5, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 80.12821% with 31 lines in your changes missing coverage. Please review.

Project coverage is 79.15%. Comparing base (a178460) to head (e4bb6a4).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ity_emb/infinity_emb/inference/loading_strategy.py 59.67% 25 Missing ⚠️
...infinity_emb/transformer/quantization/interface.py 50.00% 3 Missing ⚠️
...y_emb/transformer/embedder/sentence_transformer.py 71.42% 2 Missing ⚠️
libs/infinity_emb/infinity_emb/primitives.py 95.45% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #452      +/-   ##
==========================================
- Coverage   79.18%   79.15%   -0.04%     
==========================================
  Files          41       42       +1     
  Lines        3248     3363     +115     
==========================================
+ Hits         2572     2662      +90     
- Misses        676      701      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@michaelfeil michaelfeil merged commit 941105f into main Nov 11, 2024
36 checks passed
@michaelfeil michaelfeil deleted the model-parallel-device-interface branch November 11, 2024 06:24
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