From ecabcbd73403c23543322f34a5b70e1eacc01db2 Mon Sep 17 00:00:00 2001 From: Dmitri Khokhlov Date: Mon, 26 Feb 2024 08:41:23 -0800 Subject: [PATCH] fix: disable fast validation for now - breaks complex types (#1548) Signed-off-by: Dmitri Khokhlov --- python/cog/server/http.py | 4 +-- .../test_integration/test_predict.py | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/python/cog/server/http.py b/python/cog/server/http.py index 06507344b..ccb2f3a14 100644 --- a/python/cog/server/http.py +++ b/python/cog/server/http.py @@ -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 @@ -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 diff --git a/test-integration/test_integration/test_predict.py b/test-integration/test_integration/test_predict.py index e516562a0..311be4ad5 100644 --- a/test-integration/test_integration/test_predict.py +++ b/test-integration/test_integration/test_predict.py @@ -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"