Skip to content

Commit 2d9454d

Browse files
technilloguemattt
andcommitted
replace requests with httpx and factor out clients (#1574)
* input downloads, output uploads, and webhooks are now handled by ClientManager, which persists for the lifetime of runner, allowing us to reuse connections, which may significantly help with large uploads. * although I was originally going to drop output_file_prefix, it's not actually hard to maintain. the behavior is changed now and objects are uploaded as soon as they're outputted rather than after the prediction is completed. * there's an ugly hack with uploading an empty body to get the redirect instead of making api time out from trying to upload an 140GB file. that can be fixed by implemented an MPU endpoint and/or a "fetch upload url" endpoint. * the behavior of the non-indempotent endpoint is changed; the id is now randomly generated if it's not provided in the body. this isn't strictly required for this change alone, but is hard to carve out. * the behavior of Path is changed significantly. see https://www.notion.so/replicate/Cog-Setup-Path-Problem-2fc41d40bcaf47579ccd8b2f4c71ee24 Signed-off-by: technillogue <technillogue@gmail.com> Co-authored-by: Mattt <mattt@replicate.com> Signed-off-by: technillogue <technillogue@gmail.com>
1 parent 77b3443 commit 2d9454d

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

python/cog/predictor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def get_weights_argument(
9191
if weights_type is None:
9292
return None
9393
weights_url = os.environ.get("COG_WEIGHTS")
94-
weights_path = "weights" # this is the source of a bug isn't it?
94+
weights_path = "weights" # this is the source of a bug isn't it?
9595

9696
# TODO: Cog{File,Path}.validate(...) methods accept either "real"
9797
# paths/files or URLs to those things. In future we can probably tidy this

python/cog/server/clients.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def __init__(self) -> None:
109109
self.log = structlog.get_logger(__name__).bind()
110110

111111
async def aclose(self) -> None:
112+
# not used but it's not actually critical to close them
112113
await self.webhook_client.aclose()
113114
await self.retry_webhook_client.aclose()
114115
await self.file_client.aclose()

python/cog/server/runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ def __init__(
8989
tee_output: bool = True,
9090
) -> None:
9191
self._shutdown_event = shutdown_event # __main__ waits for this event
92+
9293
self._upload_url = upload_url
93-
self._predictions: "dict[str, tuple[schema.PredictionResponse, PredictionTask]]" = {}
94+
self._predictions: (
95+
"dict[str, tuple[schema.PredictionResponse, PredictionTask]]"
96+
) = {}
9497
self._predictions_in_flight: "set[str]" = set()
9598
# it would be lovely to merge these but it's not fully clear how best to handle it
9699
# since idempotent requests can kinda come whenever?

python/tests/server/test_webhook.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import requests
33
import responses
44
from cog.schema import WebhookEvent
5+
56
from responses import registries
67

78
pytest.skip(allow_module_level=True)

0 commit comments

Comments
 (0)