-
Notifications
You must be signed in to change notification settings - Fork 0
v1 Deploy Adjustments #23
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,11 +191,11 @@ def create_embeddings( | |
|
|
||
| # read env vars for configurations | ||
| num_workers = int(os.getenv("TE_NUM_WORKERS", "1")) | ||
| batch_size = int( | ||
| os.getenv("TE_BATCH_SIZE", "32") | ||
| ) # sentence-transformers default | ||
| batch_size = int(os.getenv("TE_BATCH_SIZE", "32")) | ||
| chunk_size_env = os.getenv("TE_CHUNK_SIZE") | ||
| chunk_size = int(chunk_size_env) if chunk_size_env else None | ||
|
|
||
| # configure device and worker pool based on number of workers requested | ||
| # configure for inference | ||
| if num_workers > 1 or self.device == "mps": | ||
| device = None | ||
| pool = self._model.start_multi_process_pool( | ||
|
|
@@ -206,17 +206,20 @@ def create_embeddings( | |
| pool = None | ||
| logger.info( | ||
| f"Num workers: {num_workers}, batch size: {batch_size}, " | ||
| f"device: {device}, pool: {pool}" | ||
| f"chunk size: {chunk_size, }device: {device}, pool: {pool}" | ||
| ) | ||
|
|
||
| # get sparse vector embedding for input text(s) | ||
| inference_start = time.perf_counter() | ||
| sparse_vectors = self._model.encode_document( | ||
| texts, | ||
| batch_size=batch_size, | ||
| device=device, | ||
| pool=pool, | ||
| save_to_cpu=True, | ||
| chunk_size=chunk_size, | ||
| ) | ||
| logger.info(f"Inference elapsed: {time.perf_counter()-inference_start}s") | ||
| sparse_vectors = cast("list[Tensor]", sparse_vectors) | ||
|
|
||
| for i, embedding_input in enumerate(embedding_inputs_list): | ||
|
|
@@ -244,8 +247,11 @@ def _get_embedding_from_sparse_vector( | |
| decoded_token_weights = cast("list[tuple[str, float]]", decoded_token_weights) | ||
| embedding_token_weights = dict(decoded_token_weights) | ||
|
|
||
| # prepare sparse vector for JSON serialization | ||
| embedding_vector = sparse_vector.to_dense().tolist() | ||
| # # prepare sparse vector for JSON serialization | ||
| # NOTE: at this time we are NOT including the sparse vector for output. This | ||
| # block can be uncommented in the future to include it when wanted. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A good approach to this change!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought you'd like this update @ehanson8! Glad we have this stubbed if we do want them in the future, but I think your instinct was right to not include them at first. Going to be lots of churn in the embeddings creation for a bit as we tune things. |
||
| # embedding_vector = sparse_vector.to_dense().tolist() # noqa: ERA001 | ||
| embedding_vector = None | ||
|
|
||
| return Embedding( | ||
| timdex_record_id=embedding_input.timdex_record_id, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate the var and logging name change for specificity on what it is tracking