cog icon indicating copy to clipboard operation
cog copied to clipboard

Disable mirroring input in output

Open djkeyes opened this issue 1 year ago • 0 comments

Hi, I noticed that when using the http API, the contents of "input" in the request get echoed back in the response. I'm working on a model that sends a few MB of string data, and I would prefer not to double my network traffic. Is it possible to disable this? (Maybe in cog.yaml? Or as an option in the request?)

From a design perspective, I feel that echoing the input is a little redundant when users are making synchronous requests (they already have the data they just sent). For asynchronous requests, that may not be the case (they may already have trashed their inputs).

Example

Here's a minimal example to show what I mean.

Setup

predict.py

from cog import BasePredictor, Input
class Predictor(BasePredictor):
    def predict(self,value: str = Input(description="The input")) -> int:
        return 42

cog.yaml

build:
  gpu: false
  python_version: "3.11"
predict: "predict.py:Predictor"

building and running

cog build -t stringizer
docker run -d -p 5000:5000 stringizer

Result

I ran the following command:

curl -X 'POST' 'http://localhost:5000/predictions' \
    -H 'accept: application/json' -H 'Content-Type: application/json' \
    -d '{ "input": { "value": "possibly a very long string" } }'

Expected

From my initial reading of the http docs, I expected to get this response:

{"output":42,"error":null,"status":"succeeded"}

Actual

The actual response was:

{"input":{"value":"possibly a very long string"},"output":42,"id":null,"version":null,"created_at":null,"started_at":"2024-03-06T19:54:00.541667+00:00","completed_at":"2024-03-06T19:54:00.542524+00:00","logs":"","error":null,"status":"succeeded","metrics":{"predict_time":0.000857},"webhook":null,"webhook_events_filter":["start","output","logs","completed"],"output_file_prefix":null}

djkeyes avatar Mar 06 '24 20:03 djkeyes