-
Notifications
You must be signed in to change notification settings - Fork 621
Add support for async predictors #1813
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
Closed
Closed
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
3277023
run CI for this branch the same way as for main
technillogue a76a012
async runner (#1352)
technillogue b947c90
support async predict functions (#1350)
technillogue 7e63a48
AsyncConcatenateIterator
technillogue 40180a8
create event loop before predictor setup (#1366)
technillogue 78879e4
minimal async worker (#1410)
technillogue 7624116
Mux prediction events (#1405)
technillogue a616653
replace requests with httpx and factor out clients (#1574, #1707, #1714)
technillogue 5904b60
implement mp.Connection with async streams (#1640)
technillogue ca14e0d
optimize webhook serialization and logging (#1651)
technillogue 2be1715
tweak names and style
technillogue da1e997
omnibus actual concurrency and major refactor (#1530)
technillogue f77c205
function to emit metrics (#1649)
technillogue 652074a
predict_time_share metric (#1643, #1683)
technillogue 840cb3c
log traceback properly (#1734)
technillogue 3875d00
add batch size metric (#1750)
technillogue 403d52e
fix various lints
technillogue 16a5811
Poison model healthcheck on shutdown
nickstenning 0955c92
Propagate trace context to webhook and upload requests
aron 66c7ed7
[async] Include prediction id upload request (#1788)
aron c856770
Passing tests
mattt 52ba22f
Revert "run CI for this branch the same way as for main"
mattt 7b69bc4
Implement webhook and file tests
mattt bd6bdf2
Add missing tests for data: URIs
mattt b215cea
Delete .tool-versions
mattt 560b665
Add pylint tool settings to pyproject.toml
mattt 59d0809
Ignore pylint warnings
mattt 46c4980
Resolve pylint warnings
mattt a73266f
Remove duplicate and unused WorkerState declaration
mattt a9cf05d
Refactor get_weights_argument
mattt 835b658
fix shutdown bugs (#1819, #1843)
technillogue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Metrics | ||
|
||
Prediction objects have a `metrics` field. This normally includes `predict_time` and `total_time`. Official language models have metrics like `input_token_count`, `output_token_count`, `tokens_per_second`, and `time_to_first_token`. Currently, custom metrics from Cog are ignored when running on Replicate. Official Replicate-published models are the only exception to this. When running outside of Replicate, you can emit custom metrics like this: | ||
|
||
|
||
```python | ||
import cog | ||
from cog import BasePredictor, Path | ||
|
||
class Predictor(BasePredictor): | ||
def predict(self, width: int, height: int) -> Path: | ||
"""Run a single prediction on the model""" | ||
cog.emit_metric(name="pixel_count", value=width * height) | ||
``` |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,13 @@ authors = [{ name = "Replicate", email = "[email protected]" }] | |
license.file = "LICENSE" | ||
urls."Source" = "https://github.com/replicate/cog" | ||
|
||
requires-python = ">=3.7" | ||
requires-python = ">=3.8" | ||
dependencies = [ | ||
# intentionally loose. perhaps these should be vendored to not collide with user code? | ||
"attrs>=20.1,<24", | ||
"fastapi>=0.75.2,<0.99.0", | ||
# we may not need http2 | ||
"httpx[http2]>=0.21.0,<1", | ||
"pydantic>=1.9,<2", | ||
"PyYAML", | ||
"requests>=2,<3", | ||
|
@@ -27,14 +29,15 @@ dependencies = [ | |
optional-dependencies = { "dev" = [ | ||
"black", | ||
"build", | ||
"httpx", | ||
'hypothesis<6.80.0; python_version < "3.8"', | ||
'hypothesis; python_version >= "3.8"', | ||
"respx", | ||
'numpy<1.22.0; python_version < "3.8"', | ||
'numpy; python_version >= "3.8"', | ||
"pillow", | ||
"pyright==1.1.347", | ||
"pytest", | ||
"pytest-asyncio", | ||
"pytest-httpserver", | ||
"pytest-rerunfailures", | ||
"pytest-xdist", | ||
|
@@ -66,6 +69,21 @@ reportUnusedExpression = "warning" | |
[tool.setuptools] | ||
package-dir = { "" = "python" } | ||
|
||
[tool.pylint.main] | ||
disable = [ | ||
"C0114", # Missing module docstring | ||
"C0115", # Missing class docstring | ||
"C0116", # Missing function or method docstring | ||
"C0301", # Line too long | ||
"C0413", # Import should be placed at the top of the module | ||
"R0903", # Too few public methods | ||
"W0622", # Redefining built-in | ||
] | ||
good-names = ["id", "input"] | ||
|
||
ignore-paths = ["python/cog/_version.py", "python/tests"] | ||
|
||
|
||
[tool.ruff] | ||
lint.select = [ | ||
"E", # pycodestyle error | ||
|
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.