Custom serverless deployment
I want to host https://hub.docker.com/r/konieshadow/fooocus-api on a serverless endpoint but i am unable to find the related documentation can someone guide me through this please?
58 Replies
Docker image won't work unless its designed specifically for RunPod serverless. Docker hub doesn't seem to indicate that its compatible with RunPod serverless so it won't work.
Yeah its FastAPI, can work on GPU cloud, but not RunPod serverless.
You either need to fork the Github or implement the cog implementation.
GitHub
GitHub - konieshadow/Fooocus-API: FastAPI powered API for Fooocus
FastAPI powered API for Fooocus. Contribute to konieshadow/Fooocus-API development by creating an account on GitHub.
RunPod Blog
Serverless | Migrating and Deploying Cog Images on RunPod Serverles...
Switching cloud platforms or migrating existing models can often feel like a Herculean task, especially when it necessitates additional developmental efforts. This guide aims to simplify this process for individuals who have deployed models via replicate.com or utilized the Cog framework. Through a few straightforward steps, you'll learn how
I have to clone cog-worker and cd into it and then do
docker build --tag mydockeruser/fooocus-api:latest --build-arg COG_REPO=konieshadow --build-arg COG_MODEL=fooocus-api
--build-arg COG_VERSION=fda927242b1db6affa1ece4f54c37f19b964666bf23b0d06ae2439067cd344a4 .
right?
Don't know, never used it, @Justin Merrell should be able to advise.
Did you already do this?
no just wanted to confirm what i understood was right before doing it
is it right?
Looks correct, yes
so will it work if the run the docker image that i built locally?
? what is the question?
Didn't make sense
If the question is will it run - yes - the docker image once u build > and push > should work
the port number shouldn't be an issue right ?
cuz fooocus api is hosted on port 8888
So I don't think the fooocus api is relevant here
so a Cog is just a standard way to wrap a model + how to use the model
And then essentially you are wrapping the model into a docker container that you can deploy on runpod, and the handler.py in runpod will call that cog
so there is no "backend api server" you are spinning up, you are just directly from the handler, triggering the cog
GitHub
cog-worker/src/handler.py at main Ā· runpod-workers/cog-worker
Cog based workers to RunPod serverless workers. . Contribute to runpod-workers/cog-worker development by creating an account on GitHub.
What we can see here is that they essentially anything in your : {input: {key key key}} gets passed along directly to Cog - the model you are prepackaging
danggg nice
i did this and pushed it to docker and used the tag to setup serverless endpoint
but since like 30 min it is stuck on initialising
May you paste the endpoint id here?
a9qygnltdyxj54
Are you using network storage or locked it to a specific region?
looks like
u forgot to tag it
username/fooocus-api:tagnumber
i did
in the template
oh yes
siddarthreddyg/fooocus-api:0.1
should be this right?
unless the screenshot was wrong and u changed after
(I still feel that runpod should add a regex validation check to these inputs š¢
yess
I changed it now
Yea haha +1 my feature request š
https://discord.com/channels/912829806415085598/1185822883474309181https://discord.com/channels/912829806415085598/1185822883474309181
Cool hopefully that solves ur issue
u wouldnt imagine how many times i did the same thing
wondering why it wouldnt work lol
šļø
it's either the max worker was set to one, which for some reason sometimes causes a weird loop, so i try to set it to 2 at minimum
or i forgot a tag
or something about my docker container is broken itself lol
it is running now š
Nice congrats
U can use their web ui to test it out
But make sure ur input is structured correctly
such as
https://github.com/runpod-workers/cog-worker/blob/main/src/handler.py
As can see here they just pass along ur full input it looks like
so input {} has the json i send as request to fooocus right?
and where do i specify the endpoint?
Yea input has the json ur sending
konieshadow/fooocus-api ā Replicate
Third party Fooocus replicate model
That is my guess
well u can run it in the web ui if u scroll down for now
but if u want to run it as a programmatic python can check out their serverless doc
Run your first AI API with Stable Diffusion | RunPod Documentation
Interact with your favorite models without managing the pods yourself.
and where do i pass the endpoint?
what do u mean the endpoint?
in ur request?
Oh
wait lol
hold on i see
in the ID section:
https://docs.runpod.io/tutorials/serverless/run-your-first
Run your first serverless endpoint with Stable Diffusion | RunPod D...
Interact with your favorite models without managing the pods yourself.
Damn idk what happened to the section in their old doc
maybe they missed a better one
Can also refer to my github repo
for examples for python
GitHub
GitHub - justinwlin/runpod_whisperx_serverless_clientside_code: Hel...
Helper functions for Runpod to automatically poll my WhisperX API. Can be adapted to other use cases - justinwlin/runpod_whisperx_serverless_clientside_code
yea but this section
brooo lmfao
how hard do i cry? š
Amazing, I may have time to convert this thing into a RunPod worker for you tomorrow.
Or is the bas64 actually valid?
i think it is valid
i need to check
its just tooo long
Sounds like a good sign then š
lmao
You can prob ask chatgpt to add a bit of logic to the docker from runpod:
IN this section
GitHub
GitHub - davefojtik/RunPod-Fooocus-API at Standalone
RunPod serverless worker for Fooocus-API. Standalone or with network volume - GitHub - davefojtik/RunPod-Fooocus-API at Standalone
rather than return the json["output"]
Before that you do:
base64 = base64 convert json "url" or something
return base64
wow nice
xD
this also works hhh
GitHub
GitHub - davefojtik/RunPod-Fooocus-API at Standalone
RunPod serverless worker for Fooocus-API. Standalone or with network volume - GitHub - davefojtik/RunPod-Fooocus-API at Standalone
u want the standalone one
but seems like
3wad/runpod-fooocus-api:0.3.30-standalone
they also just have a docker image
they deployed
u can prob just try to deploy that
but i guess the issue is
ull have to figure out their api
vs cog is well documented
tbh i think u can just add a bit more logic to the json u got out
ask chatgpt how to grab the image and do a bit more testing with it
yeah i made my own docker using cog
but how i am unable to figureout the api
can you help me with that
?
would the input be something like this?
or
Uh, I really dont know that highly highly depends on ur own cog.
but runpod expects:
And what it will pass to ur cog is:
what if my cog has 3-4 apii endpoints?
This is what runpod passes:
https://github.com/runpod-workers/cog-worker/blob/main/src/handler.py
is that possible? wouldn't the cog probably be expecting something in the JSON to differentiate?
Im not familiar with Cogs, but isnt the cog just a standard way to wrap an ML model for the prediction? so it probably some sort of if-statement right based off of the json?
GitHub
Fooocus-API/docs/api_doc_en.md at 074a956d2fc6e12e9b669cfe6611fd576...
FastAPI powered API for Fooocus. Contribute to konieshadow/Fooocus-API development by creating an account on GitHub.
Yea that isnt the cog
that just a backend api that spins up to call the cog
https://github.com/konieshadow/Fooocus-API/blob/074a956d2fc6e12e9b669cfe6611fd576dd7e315/predict.py
This is the Cog
https://replicate.com/konieshadow/fooocus-api?input=python
U can look at their python Json to see sort of how it would look being passed into the cog
Guessing what u would give runpod looks like below:
which then runpod would take ur input, and pass it to the Cog predictor function
Cog is essentially a function
So you just call the function.
The backend server you showed is like, oh if you go to this URL, Ill pass these parameters to the Cog function, but u dont have a backend server ur spinning up, ur just directly calling the Cog function with the json input
ohh
okay okay
now it is slowly starting to make sense
but in the backend i have an option to send image as base64 how do i do that here?
Not 100% sure my guess is that you'll need to modify the handler a bit:
https://github.com/konieshadow/Fooocus-API/blob/074a956d2fc6e12e9b669cfe6611fd576dd7e315/predict.py
If you look here it expects a :Path type, (thank god for this author having good typing) - it probably means FilePath is my guess
What that probably means is that when you get the json:
Before you pass it, you prob go like:
does xyz key exist, if so, write the base64 to an image, and replace the base64 value with the path i wrote too. Before it runs the inference
U can try to trace down how their API endpoint works, but that just my best guess looking at it