Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,3 @@ jobs:
pip install -r requirements.txt
- name: Test
run: make test

release:
needs: [test, test-end-to-end]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-go@v2
with:
go-version: 1.16
- uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 0 additions & 28 deletions .goreleaser.yml

This file was deleted.

42 changes: 8 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ model: "model.py:JazzSoloComposerModel"
3. Build and push the model:

```
$ cog remote set http://10.1.2.3:8000
$ cog repo set http://10.1.2.3:8000
$ cog build
...
--> Built and pushed b6a2f8a2d2ff
Expand Down Expand Up @@ -82,13 +82,9 @@ When that has finished, you can run inferences on the built model from any machi

cog infer b31f9f72d8f14f0eacc5452e85b05c957b9a8ed9 -i @hotdog.jpg

You can list packages to see the built package:

cog list

You can see more details about the package:

cog show b31f9f72d8f14f0eacc5452e85b05c957b9a8ed9
cog show b31f9f72d8f14f0eacc5452e85b05c957b9a8ed9

In this output is the Docker image. You can run this anywhere a Docker image runs to deploy your model.

Expand All @@ -100,14 +96,14 @@ No docs yet -- sorry! It should be pretty self-explanatory from the examples.

## Server API

### POST `/v1/packages/upload`
### PUT `/v1/packages/<user>/<name>/`

Upload a new package.

Example:

```
$ curl -X POST localhost:8080/v1/packages/upload -F "[email protected]"
$ curl -X PUT localhost:8080/v1/packages/andreas/my-model/ -F "[email protected]"
```

where `package.zip` is a zip folder of a directory with `cog.yaml` in it.
Expand All @@ -120,25 +116,23 @@ This does the following:
* Tests that the model works by running the Docker image locally and performing an inference
* Inserts model metadata into database (local files)

### GET `/v1/packages/<id>`
### GET `/v1/packages/<user>/<name>`

Fetch package metadata.

Example:

```
$ curl localhost:8080/v1/packages/c43b98b37776656e6b3dac3ea3270660ffc21ca7 | jq .
$ curl localhost:8080/v1/packages/andreas/my-model/c43b98b37776656e6b3dac3ea3270660ffc21ca7 | jq .
{
"ID": "c43b98b37776656e6b3dac3ea3270660ffc21ca7",
"Name": "andreas/scratch",
"Artifacts": [
{
"Target": "docker-cpu",
"URI": "us-central1-docker.pkg.dev/replicate/andreas-scratch/andreas/scratch:2c7492b7d3d6"
}
],
"Config": {
"Name": "andreas/scratch",
"Environment": {
"PythonVersion": "3.8",
"PythonRequirements": "",
Expand All @@ -155,36 +149,16 @@ $ curl localhost:8080/v1/packages/c43b98b37776656e6b3dac3ea3270660ffc21ca7 | jq
}
```

### GET `/v1/packages/<id>.zip`
### GET `/v1/packages/<user>/<name>/<id>.zip`

Download the package.

Example:

```
$ curl localhost:8080/v1/packages/c43b98b37776656e6b3dac3ea3270660ffc21ca7.zip > my-package.zip
$ curl localhost:8080/v1/packages/andreas/my-model/c43b98b37776656e6b3dac3ea3270660ffc21ca7.zip > my-package.zip
$ unzip my-package.zip
Archive: my-package.zip
inflating: cog.yaml
inflating: infer.py
```

### GET `/v1/packages/`

List all packages.

Example:

```
$ curl localhost:8080/v1/packages/ | jq .
[
{
"ID": "af3ff5288247833f5f9d8d9f6ecd5fe2b586f6aa",
"Name": "andreas/fastgan",
"Artifacts": [
{
"Target": "docker-cpu",
"URI": "us-central1-docker.pkg.dev/replicate/andreas-scratch/andreas/fastgan:a034b8a9bf46"
},
[...]
```
62 changes: 38 additions & 24 deletions end-to-end-test/end_to_end_test/test_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random
import string
from glob import glob
import os
from os.path import basename
import tempfile
import socket
from contextlib import closing
Expand All @@ -25,31 +26,19 @@ def cog_server_port_dir():
)
assert resp.text == "pong"

out, err = subprocess.Popen(
["cog", "remote"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).communicate()
old_remote = out.decode().strip()

out, err = subprocess.Popen(
["cog", "remote", "set", "http://localhost:" + port],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).communicate()
assert out.decode() == f"Updated remote: http://localhost:{port}\n"
assert err == b""

yield port, cog_dir

os.chdir(old_cwd)
server_proc.kill()

subprocess.Popen(["cog", "remote", "set", old_remote]).communicate()


def test_build_show_list_download_infer(cog_server_port_dir, tmpdir_factory):
cog_port, cog_dir = cog_server_port_dir

user = "".join(random.choice(string.ascii_lowercase) for i in range(10))
repo_name = "".join(random.choice(string.ascii_lowercase) for i in range(10))
repo = f"localhost:{cog_port}/{user}/{repo_name}"

project_dir = tmpdir_factory.mktemp("project")
with open(project_dir / "infer.py", "w") as f:
f.write(
Expand Down Expand Up @@ -88,6 +77,13 @@ def run(self, text, path):
"""
)

out, _ = subprocess.Popen(
["cog", "repo", "set", f"localhost:{cog_port}/{user}/{repo_name}"],
stdout=subprocess.PIPE,
cwd=project_dir,
).communicate()
assert out.decode() == f"Updated repo: localhost:{cog_port}/{user}/{repo_name}\n"

with open(project_dir / "myfile.txt", "w") as f:
f.write("baz")

Expand All @@ -103,19 +99,25 @@ def run(self, text, path):
package_id = out.decode().strip().split("Successfully built ")[1]

out, _ = subprocess.Popen(
["cog", "show", package_id], stdout=subprocess.PIPE
["cog", "-r", repo, "show", package_id], stdout=subprocess.PIPE
).communicate()
lines = out.decode().splitlines()
assert lines[0] == f"ID: {package_id}"
assert lines[1] == "Name: andreas/hello-world"
assert lines[1] == f"Repo: {user}/{repo_name}"

out, _ = subprocess.Popen(["cog", "ls"], stdout=subprocess.PIPE).communicate()
# show without -r
out, _ = subprocess.Popen(
["cog", "show", package_id],
stdout=subprocess.PIPE,
cwd=project_dir,
).communicate()
lines = out.decode().splitlines()
assert lines[1].startswith(f"{package_id} andreas/hello-world")
assert lines[0] == f"ID: {package_id}"
assert lines[1] == f"Repo: {user}/{repo_name}"

download_dir = tmpdir_factory.mktemp("download") / "my-dir"
subprocess.Popen(
["cog", "download", "--output-dir", download_dir, package_id],
["cog", "-r", repo, "download", "--output-dir", download_dir, package_id],
stdout=subprocess.PIPE,
).communicate()
paths = sorted(glob(str(download_dir / "*.*")))
Expand All @@ -129,7 +131,19 @@ def run(self, text, path):

out_path = output_dir / "out.txt"
subprocess.Popen(
["cog", "infer", "-o", out_path, "-i", "text=baz", "-i", f"path=@{input_path}", package_id],
[
"cog",
"-r",
repo,
"infer",
"-o",
out_path,
"-i",
"text=baz",
"-i",
f"path=@{input_path}",
package_id,
],
stdout=subprocess.PIPE,
).communicate()
with out_path.open() as f:
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/docker/go-units v0.4.0 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/go-cmp v0.5.4 // indirect
github.com/gopherdata/gophernotes v0.7.2 // indirect
github.com/gorilla/mux v1.8.0
github.com/kr/text v0.2.0 // indirect
github.com/mholt/archiver/v3 v3.5.0
Expand All @@ -23,6 +24,8 @@ require (
github.com/onsi/gomega v1.4.3 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/pebbe/zmq4 v0.0.0-20170917105202-90d69e412a09 // indirect
github.com/satori/go.uuid v1.2.1-0.20180103174451-36e9d2ebbde5 // indirect
github.com/schollz/progressbar/v3 v3.7.6
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.3
Expand Down
Loading