Skip to content

Commit

Permalink
fix: disable fast validation for now - breaks complex types (#1548)
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitri Khokhlov <dkhokhlov@gmail.com>
  • Loading branch information
dkhokhlov committed Feb 26, 2024
1 parent 241d5c1 commit ecabcbd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/cog/server/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def start_shutdown() -> Any:
try:
predictor_ref = get_predictor_ref(config, mode)
# use bundled schema if it exists
schema_module = schema.create_schema_module()
schema_module = None # schema.create_schema_module() - breaks complex types, always use slow path for now
if schema_module is not None:
log.info("using bundled schema")
InputType = schema_module.Input
Expand Down Expand Up @@ -173,7 +173,7 @@ async def wrapped(*args: "P.args", **kwargs: "P.kwargs") -> "T":
try:
trainer_ref = get_predictor_ref(config, "train")
# use bundled schema if it exists
schema_module = schema.create_schema_module()
schema_module = None # schema.create_schema_module() - breaks complex types, always use slow path for now
if schema_module is not None:
log.info("using bundled schema")
TrainingInputType = schema_module.TrainingInputType
Expand Down
36 changes: 36 additions & 0 deletions test-integration/test_integration/test_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,39 @@ def test_predict_many_inputs(tmpdir_factory):
capture_output=True,
)
assert result.stdout.decode() == "hello default 20 world jpg foo 6\n"


def test_predict_many_inputs_with_existing_image(docker_image, tmpdir_factory):
project_dir = Path(__file__).parent / "fixtures/many-inputs-project"

subprocess.run(
["cog", "build", "-t", docker_image],
cwd=project_dir,
check=True,
)

out_dir = pathlib.Path(tmpdir_factory.mktemp("project"))
shutil.copytree(project_dir, out_dir, dirs_exist_ok=True)
inputs = {
"no_default": "hello",
"path": "@path.txt",
"image": "@image.jpg",
"choices": "foo",
"int_choices": 3,
}
with open(out_dir / "path.txt", "w") as fh:
fh.write("world")
with open(out_dir / "image.jpg", "w") as fh:
fh.write("")
cmd = ["cog", "predict", docker_image]

for k, v in inputs.items():
cmd += ["-i", f"{k}={v}"]

result = subprocess.run(
cmd,
cwd=out_dir,
check=True,
capture_output=True,
)
assert result.stdout.decode() == "hello default 20 world jpg foo 6\n"

0 comments on commit ecabcbd

Please sign in to comment.