mrhan1993 / Fooocus-API

FastAPI powered API for Fooocus
GNU General Public License v3.0
528 stars 142 forks source link

Memory leak in Docker container after processing an image #141

Closed siddarthreddygsr closed 6 months ago

siddarthreddygsr commented 6 months ago

I am hosting the docker container by following the steps in the README docker run --gpus=all -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -e NVIDIA_VISIBLE_DEVICES=all -p 8888:8888 konies but when I make an API call like this

import requests
import mimetypes
from maskgen import generate_mask

def get_content_type(filename):
    return mimetypes.guess_type(filename)[0] or 'application/octet-stream'

def post_image_inpaint_outpaint(input_image_path, input_mask_path):
    url = 'http://127.0.0.1:8888/v1/generation/image-inpait-outpaint'
    files = {
        'sharpness': (None, '2'),
        'input_mask': (input_mask_path, open(input_mask_path, 'rb'), get_content_type(input_mask_path)),
        'outpaint_distance_right': (None, '0'),
        'loras': (None, '[{"model_name":"sd_xl_offset_example-lora_1.0.safetensors","weight":0.1}]'),
        'outpaint_distance_left': (None, '0'),
        'advanced_params': (None, ''),
        'guidance_scale': (None, '4'),
        'prompt': (None, 'A serene landscape with rolling green hills under a clear blue sky.'),
        'input_image': (input_image_path, open(input_image_path, 'rb'), get_content_type(input_image_path)),
        'outpaint_distance_bottom': (None, '0'),
        'require_base64': (None, 'false'),
        'async_process': (None, 'false'),
        'image_number': (None, '1'),
        'negative_prompt': (None, 'No buildings, people, or animals. Avoid dark, gloomy weather.'),
        'refiner_switch': (None, '0.5'),
        'base_model_name': (None, 'juggernautXL_version6Rundiffusion.safetensors'),
        'image_seed': (None, "-1"),
        'style_selections': (None, 'Fooocus V2,Fooocus Enhance,Fooocus Sharp'),
        'inpaint_additional_prompt': (None, ''),
        'outpaint_selections': (None, ''),
        'outpaint_distance_top': (None, '0'),
        'refiner_model_name': (None, 'None'),
        'aspect_ratios_selection': (None, '1152*896'),
        'performance_selection': (None, 'Speed'),
    }

    response = requests.post(url, files=files)
    return response

input_image_path = '1.jpg'
input_mask_path = "mask.jpg"
response = post_image_inpaint_outpaint(input_image_path, input_mask_path)

if response.ok:
    print("Success:", response.json())
else:
    print("Error:", response.status_code, response.text)

it works fine for the first image but after the first image is generated the system RAM is almost full and it when I run it on a second image it overflows the memory and crashes the system.

image
mrhan1993 commented 6 months ago

increase your swap memory or use -m flay to limit container usage

docker run --gpus=all \
    -m 8192m \
    -e NVIDIA_DRIVER_CAPABILITIES=compute,utility \
    -e NVIDIA_VISIBLE_DEVICES=all -p 8888:8888 konies