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

Improve: batch size setting and multi GPU inference with SentenceTransformers+DP #53

Merged
merged 17 commits into from
Aug 13, 2024

Conversation

akiFQC
Copy link
Collaborator

@akiFQC akiFQC commented Aug 8, 2024

関連する Issue / PR

PR をマージした後の挙動の変化

  • バッチサイズを最適化して高速に埋め込みを計算したい
  • 安定性のために、torchrun を使わずにGPU並列化を行いたい

挙動の変更を達成するために行ったこと

  • src/jmteb/embedders/base.pyTextEmbedder_chunk_size という変数を追加し、_chunk_size ごとに TextEmbedder.encodeを呼ぶように変更
  • src/jmteb/embedders/data_parallel_sbert_embedder.py追加し、sentence-transfermersでpytorchのDataParallelによる複数GPU推論が可能になった。
  • テストを追加

動作確認

  • テストが通ることを確認した
  • マージ先がdevブランチであることを確認した

@akiFQC akiFQC requested a review from lsz05 August 9, 2024 00:41
OUTPUT_DIM = 128


class TestSentenceBertEmbedder:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
class TestSentenceBertEmbedder:
class TestDPSentenceBertEmbedder:


def _add_eos_func(self, text: str | list[str]) -> str | list[str]:
try:
eos_token = getattr(self.model.savetokenizer, "eos_token")
Copy link
Collaborator

Choose a reason for hiding this comment

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

self.model.tokenizer?

@lsz05
Copy link
Collaborator

lsz05 commented Aug 9, 2024

起動時torchrunではなくpythonで起動すると理解合っていますでしょうか?

@akiFQC
Copy link
Collaborator Author

akiFQC commented Aug 9, 2024

起動時torchrunではなくpythonで起動すると理解合っていますでしょうか?

はい。pythonで起動してください。

@akiFQC akiFQC marked this pull request as ready for review August 9, 2024 06:30
Copy link
Collaborator

@lsz05 lsz05 left a comment

Choose a reason for hiding this comment

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

LGTMです!

self.model = self.dp_model.sbert
if max_seq_length:
self.model.max_seq_length = max_seq_length
self.initital_batch_size = batch_size
Copy link
Collaborator

Choose a reason for hiding this comment

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

self.initial_batch_sizeが使われていないような気がしますが

@akiFQC akiFQC merged commit ca71155 into dev Aug 13, 2024
3 checks passed
@lsz05 lsz05 mentioned this pull request Aug 19, 2024
1 task
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