Closed
Conversation
nabenabe0928
commented
Jan 7, 2025
| DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S.%f" | ||
|
|
||
|
|
||
| class OptunaStorageProxyService(StorageServiceServicer): |
Contributor
Author
There was a problem hiding this comment.
As Git messed up the difference between before and after, I will concisely write down the overview.
Before:
from optuna.storages._grpc.grpc_imports import _imports
if _imports.is_successful():
from optuna.storages._grpc.grpc_imports import StorageServiceServicer
else:
class StorageServiceServicer: # type: ignore
pass
class OptunaStorageProxyService(StorageServiceServicer):
...
def make_server(
storage: BaseStorage, host: str, port: int, thread_pool: ThreadPoolExecutor | None = None
) -> grpc.Server:
server = grpc.server(thread_pool or ThreadPoolExecutor(max_workers=10))
api_pb2_grpc.add_StorageServiceServicer_to_server(
OptunaStorageProxyService(storage), server
) # type: ignore
server.add_insecure_port(f"{host}:{port}")
return serverAfter:
api_pb2_grpc = _LazyImport("optuna.storages._grpc.auto_generated.api_pb2_grpc")
def make_server(
storage: BaseStorage, host: str, port: int, thread_pool: ThreadPoolExecutor | None = None
) -> grpc.Server:
class OptunaStorageProxyService(api_pb2_grpc.StorageServiceServicer):
...
server = grpc.server(thread_pool or ThreadPoolExecutor(max_workers=10))
api_pb2_grpc.add_StorageServiceServicer_to_server(
OptunaStorageProxyService(storage), server
) # type: ignore
server.add_insecure_port(f"{host}:{port}")
return server
Member
|
@kAIto47802 Could you review this PR? |
Contributor
Author
|
I will close this PR because the import time difference is not super huge (-6.8%):
|
This was referenced Jan 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
As gRPC did not use lazy import, which potentially reduces the import time, I replaced
try_importwith_LazyImport.This PR is a followup of:
Description of the changes
try_importwith_LazyImport