Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run using docker-compose with GPU and CPU support #404

Closed
wants to merge 3 commits into from

Conversation

janettefuchs
Copy link

@janettefuchs janettefuchs commented Jun 9, 2023

I think I've got all the requirements from https://github.com/s0md3v/roop/issues/171#issuecomment-1584142177 except for the REST service:

  • Create a service that translates from REST to CLI for easier use (HTTPie-Server).
  • Allow for sending a POST with headless args and retrieving output once ready.

I don't know how to implement those two in Python.

@janettefuchs janettefuchs changed the title Docker compose Run using docker-compose with GPU and CPU support Jun 9, 2023
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried if the GPU usage works in Docker with this PR and everything seems fine, except ffmpeg using hwaccel for en-/decoding.

To solve this, you need to change this line to:

capabilities: [gpu,video]

which I can confirm fixes the problem and was found here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I've added video capability and that removed the warning in ffmpeg execution.

@@ -0,0 +1,4 @@
.cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this file - please undo

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this file to prevent unnecessary file transfer between the Docker CLI and Docker Daemon when building the Docker Image. Here is documentation on how it works: https://docs.docker.com/engine/reference/builder/#dockerignore-file
This is the best practice when building Docker Images.

*.onnx
Copy link
Contributor

@henryruhs henryruhs Jun 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo the changes in .gitignore

RUN apt-get update && apt-get install -y \
ffmpeg

WORKDIR /app
Copy link
Contributor

@henryruhs henryruhs Jun 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WORKDIR is not needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed for the following ADD commands to copy the files to the correct directory


WORKDIR /app

ADD requirements.txt .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all the ADD and RUN git clone instead and checkout roop with the next branch

This comment was marked as off-topic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I set the requirements for a reason... not asking for a development container but for a production container. It seems you continue to ignore this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the best practice on building Docker Images in CI Pipelines. In the CI Pipeline you only need to run:

docker-compose build
docker-compose push

And the images will be published to Docker Hub for public use. The published images are in no way dependent on the Git Repository.

If you want to clone the Git Repository in your CI Pipeline, you will somehow have to tell which commit to checkout or which branch. By building the Docker Images the way it's done in this pull request it happens automatically. The CI Pipeline will build exactly the commit that's been tested and built.

This comment was marked as off-topic.

ADD requirements.txt .
RUN pip install -r requirements.txt

ADD inswapper_128.onnx .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this ADD have to be removed - in next branch loading the models also happens automatically now

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be placed into cache then, so that it won't be downloaded on each run.


RUN mkdir /cache

ENTRYPOINT ["python", "/app/run.py"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENTRYPOINT ["python", "run.py"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First you say WORKDIR /app is not needed, then you say ENTRYPOINT ["python", "run.py"]. How should Python find run.py without the WORKDIR or without the absolute path.
As far as I remember, Python says "explicit is better than implicit".

ADD run.py .
ADD roop roop

ENV HOME=/cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all that cache stuff... not needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache is needed unless you want roop to download those files each time after you build a new Docker Image when you change a single line of code. Docker Containers are ephemeral. Unless the cache is persisted in a volume, it will be downloaded on each new start.

@@ -0,0 +1,25 @@
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply all the changes from the main Dockerfile

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment. Which changes? The Dockerfiles for cuda and cpu are different, because there is no common base. cuda image is based on nvidia/cuda and the cpu image is based on python.

@@ -0,0 +1,25 @@
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename file to Dockerfile.cuda

@@ -0,0 +1,19 @@
FROM python:3.11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename file to Dockerfile

@@ -0,0 +1,65 @@
# Running roop in Docker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need a README, the final version just needs a docker-compose up :-)

build:
context: ..
dockerfile: docker/Dockerfile.cpu
volumes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expose the temp and output folder

volumes:
  - roop/output:/home/node/roop/output
  - roop/temp:/home/node/roop/temp

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really want to have them as Docker Volumes or do you want to bind-mount a directory from the host?
Bind-mounting a directory would be (the prepending ./ makes it a bind-mount):

services:
  roop:
    volumes:
      - ./roop/output:/home/node/roop/output
      - ./roop/temp:/home/node/roop/temp

Mounting a volume would be (can't have slashes in volume name):

services:
  roop:
    volumes:
      - output:/home/node/roop/output
      - temp:/home/node/roop/temp
volumes:
  output:
  temp:

@@ -0,0 +1,21 @@
services:
roop-cpu: &base
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roop without cpu

- ../.github/examples:/data
- ../.cache:/cache
user: 1000:1000
roop-nvidia:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roop-cuda

@@ -12,7 +11,7 @@ onnxruntime==1.15.0; sys_platform == 'darwin' and platform_machine != 'arm64'
onnxruntime-silicon==1.13.1; sys_platform == 'darwin' and platform_machine == 'arm64'
onnxruntime-gpu==1.15.0; sys_platform != 'darwin'
tensorflow==2.13.0rc1; sys_platform == 'darwin'
tensorflow==2.12.0; sys_platform != 'darwin'
tensorflow==2.13.0rc1; sys_platform != 'darwin'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't be able to install all the dependencies, because requirements.txt is broken at the moment. There is a conflict on the required version of transient numpy.

Repository owner deleted a comment from c4tz Jun 11, 2023
@janettefuchs
Copy link
Author

Feel free to close this pull request. You may use it as a good starting point to build the thing you want to achieve, whatever it may be.

@henryruhs henryruhs closed this Jun 11, 2023
kurtarma34 pushed a commit to kurtarma34/roop that referenced this pull request Aug 25, 2024
* Rename landmark 5 variables

* Mark as NEXT

* Render tabs for multiple ui layout usage

* Allow many face detectors at once, Add face detector tweaks

* Remove face detector tweaks for now (kinda placebo)

* Fix lint issues

* Allow rendering the landmark-5 and landmark-5/68 via debugger

* Fix naming

* Convert face landmark based on confidence score

* Convert face landmark based on confidence score

* Add scrfd face detector model (#397)

* Add scrfd face detector model

* Switch to scrfd_2.5g.onnx model

* Just some renaming

* Downgrade OpenCV, Add SYSTEM_VERSION_COMPAT=0 for MacOS

* Improve naming

* prepare detect frame outside of semaphore

* Feat/process manager (#399)

* Minor naming

* Introduce process manager to start and stop

* Introduce process manager to start and stop

* Introduce process manager to start and stop

* Introduce process manager to start and stop

* Introduce process manager to start and stop

* Remove useless test for now

* Avoid useless variables

* Show stop once is_processing is True

* Allow to stop ffmpeg processing too

* Implement output image resolution (#403)

* Implement output image resolution

* Reorder code

* Simplify output logic and therefore fix bug

* Frame-enhancer-onnx (s0md3v#404)

* changes

* changes

* changes

* changes

* add models

* update workflow

* Some cleanup

* Some cleanup

* Feat/frame enhancer polishing (#410)

* Some cleanup

* Polish the frame enhancer

* Frame Enhancer: Add more models, optimize processing

* Minor changes

* Improve readability of create_tile_frames and merge_tile_frames

* We don't have enough models yet

* Feat/face landmarker score (#413)

* Introduce face landmarker score

* Fix testing

* Fix testing

* Use release for score related sliders

* Reduce face landmark fallbacks

* Scores and landmarks in Face dict, Change color-theme in face debugger

* Scores and landmarks in Face dict, Change color-theme in face debugger

* Fix some naming

* Add 8K support (for whatever reasons)

* Fix testing

* Using get() for face.landmarks

* Introduce statistics

* More statistics

* Limit the histogram equalization

* Enable queue() for default layout

* Improve copy_image()

* Fix error when switching detector model

* Always set UI values with globals if possible

* Use different logic for output image and output video resolutions

* Enforce re-download if file size is off

* Remove unused method

* Remove unused method

* Remove unused warning filter

* Improved output path normalization (s0md3v#419)

* Handle some exceptions

* Handle some exceptions

* Cleanup

* Prevent countless thread locks

* Listen to user feedback

* Fix webp edge case

* Feat/cuda device detection (s0md3v#424)

* Introduce cuda device detection

* Introduce cuda device detection

* it's gtx

* Move logic to run_nvidia_smi()

* Finalize execution device naming

* Finalize execution device naming

* Merge execution_helper.py to execution.py

* Undo lowercase of values

* Undo lowercase of values

* Finalize naming

* Add missing entry to ini

* fix lip_syncer preview (#426)

* fix lip_syncer preview

* change

* Refresh preview on trim changes

* Cleanup frame enhancers and remove useless scale in merge_video() (s0md3v#428)

* Keep lips over the whole video once lip syncer is enabled (s0md3v#430)

* Keep lips over the whole video once lip syncer is enabled

* changes

* changes

* Fix spacing

* Use empty audio frame on silence

* Use empty audio frame on silence

* Fix ConfigParser encoding (#431)

facefusion.ini is UTF8 encoded but config.py doesn't specify encoding which results in corrupted entries when non english characters are used. 

Affected entries:
source_paths
target_path
output_path

* Adjust spacing

* Improve the GTX 16 series detection

* Use general exception to catch ParseError

* Use general exception to catch ParseError

* Host frame enhancer models4

* Use latest onnxruntime

* Minor changes in benchmark UI

* Different approach to cancel ffmpeg process

* Add support for amd amf encoders (#433)

* Add amd_amf encoders

* remove -rc cqp from amf encoder parameters

* Improve terminal output, move success messages to debug mode

* Improve terminal output, move success messages to debug mode

* Minor update

* Minor update

* onnxruntime 1.17.1 matches cuda 12.2

* Feat/improved scaling (#435)

* Prevent useless temp upscaling, Show resolution and fps in terminal output

* Remove temp frame quality

* Remove temp frame quality

* Tiny cleanup

* Default back to png for temp frames, Remove pix_fmt from frame extraction due mjpeg error

* Fix inswapper fallback by onnxruntime

* Fix inswapper fallback by major onnxruntime

* Fix inswapper fallback by major onnxruntime

* Add testing for vision restrict methods

* Fix left / right face mask regions, add left-ear and right-ear

* Flip right and left again

* Undo ears - does not work with box mask

* Prepare next release

* Fix spacing

* 100% quality when using jpg for temp frames

* Use span_kendata_x4 as default as of speed

* benchmark optimal tile and pad

* Undo commented out code

* Add real_esrgan_x4_fp16 model

* Be strict when using many face detectors

---------

Co-authored-by: Harisreedhar <46858047+harisreedhar@users.noreply.github.com>
Co-authored-by: aldemoth <159712934+aldemoth@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants