Commit a94695e5 authored by PengGao's avatar PengGao Committed by GitHub
Browse files

Implement distributed inference API server with FastAPI (#60)

* Implement distributed inference API server with FastAPI

- Added a new file `api_server_dist.py` to handle video generation tasks using distributed inference.
- Introduced endpoints for task submission, status checking, and result retrieval.
- Implemented image downloading and task management with error handling.
- Enhanced `infer.py` to ensure proper initialization of distributed processes.
- Created a shell script `start_api_with_dist_inference.sh` for easy server startup with environment setup.

This commit establishes a robust framework for managing video generation tasks in a distributed manner.

* Enhance file download endpoint with path traversal protection and error handling

* style: format

* refactor: Enhance video generation functionality with task interruption support

* feat: Add image upload and video generation endpoint with unique task handling

- Introduced a new endpoint `/v1/local/video/generate_form` for video generation that accepts image uploads.
- Implemented unique filename generation for uploaded images to prevent conflicts.
- Enhanced directory management for input and output paths.
- Improved file download response with detailed status and size information.
- Added error handling for distributed inference processes and graceful shutdown procedures.
parent a5535e49
This diff is collapsed.
...@@ -25,7 +25,8 @@ def init_runner(config): ...@@ -25,7 +25,8 @@ def init_runner(config):
seed_all(config.seed) seed_all(config.seed)
if config.parallel_attn_type: if config.parallel_attn_type:
dist.init_process_group(backend="nccl") if not dist.is_initialized():
dist.init_process_group(backend="nccl")
if CHECK_ENABLE_GRAPH_MODE(): if CHECK_ENABLE_GRAPH_MODE():
default_runner = RUNNER_REGISTER[config.model_cls](config) default_runner = RUNNER_REGISTER[config.model_cls](config)
......
#!/bin/bash
# 设置路径
lightx2v_path=/mnt/aigc/users/lijiaqi2/ComfyUI/custom_nodes/ComfyUI-Lightx2vWrapper/lightx2v
model_path=/mnt/aigc/users/lijiaqi2/wan_model/Wan2.1-I2V-14B-720P-cfg
# 检查参数
if [ -z "${CUDA_VISIBLE_DEVICES}" ]; then
cuda_devices=2,3
echo "Warn: CUDA_VISIBLE_DEVICES is not set, using default value: ${cuda_devices}"
export CUDA_VISIBLE_DEVICES=${cuda_devices}
fi
if [ -z "${lightx2v_path}" ]; then
echo "Error: lightx2v_path is not set. Please set this variable first."
exit 1
fi
if [ -z "${model_path}" ]; then
echo "Error: model_path is not set. Please set this variable first."
exit 1
fi
# 设置环境变量
export TOKENIZERS_PARALLELISM=false
export PYTHONPATH=${lightx2v_path}:$PYTHONPATH
export ENABLE_PROFILING_DEBUG=true
export ENABLE_GRAPH_MODE=false
echo "=========================================="
echo "启动分布式推理API服务器"
echo "模型路径: $model_path"
echo "CUDA设备: $CUDA_VISIBLE_DEVICES"
echo "API端口: 8000"
echo "=========================================="
# 启动API服务器,同时启动分布式推理服务
python -m lightx2v.api_server_dist \
--model_cls wan2.1 \
--task i2v \
--model_path $model_path \
--config_json ${lightx2v_path}/configs/wan_i2v_dist.json \
--port 8000 \
--start_inference \
--nproc_per_node 2
echo "服务已停止"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment