Files
BGfilter/configs/gpu.yaml
lhk229 07ba02fdde Make the pipelining knobs config-file settable (server: section)
CPU_WORKERS / GPU_CONCURRENCY were env-only. Add a `server:` config
section (server.cpu_workers, server.gpu_concurrency) so a lane's
concurrency lives in its yaml alongside device/precision, matching how
model.device already works. Precedence mirrors BGFILTER_DEVICE: config is
the default, the env var overrides per box.

The pool + admission semaphore now build in lifespan (after the config
loads) instead of at import, and PipelineManager reads gpu_concurrency
from the settings. configs/gpu.yaml ships 8 / 2 (its target is the 32 GB
GPU boxes) with an inline VRAM caveat: gpu_concurrency>1 must fit
weights + N × forward, so keep it 1 on ≤16 GB cards.

Verified on a 4080 SUPER: startup logs cpu_workers=8 gpu_concurrency=2
from gpu.yaml with no env set, request returns a valid RGBA.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 12:58:15 +00:00

88 lines
2.8 KiB
YAML

# GPU lane: CUDA + bf16 across all three models. Full pipeline (BiRefNet seg +
# ViTMatte + HR-matting cross-check). Foreground estimation auto-uses the CuPy GPU
# backend when cupy is installed (see foreground.use_gpu, default on). despill is
# off (it false-positives on subjects sharing the background hue).
screen_color: null
chroma:
# true = flat-colour background (default). false = non-flat/complex background
# mode: no colour key; segmentation alone drives the trimap (mode forced to
# "seg") and the colour-keyed stages are bypassed (auto-detect, hue split,
# chroma suppression, despill). The cross-check veto still runs if enabled,
# using its hue-free gate (cross_check.second_lo/hi). The service selects this
# per request via background_mode=flat|complex; this is only the base default.
enabled: true
model:
model_name: hustvl/vitmatte-base-composition-1k
device: cuda
matting_method: vitmatte
fallback_to_chroma_alpha: false
precision: bf16
attn_query_chunk: 2048
segmentation:
enabled: true
backend: birefnet
model_name: ZhengPeng7/BiRefNet
device: cuda
input_size: 1024
precision: bf16
trimap:
sure_bg_threshold: 0.92
sure_fg_threshold: 0.12
unknown_radius_ratio: 0.012
fg_safe_radius_ratio: 0.006
seg_core_threshold: 0.60
seg_loose_threshold: 0.08
mode: directional
seg_low: 0.15
bg_hue_proj_min: 4.0
seg_force_fg: 0.98
alpha_post:
chroma_suppress: true
chroma_suppress_bg_low: 0.35
chroma_suppress_bg_high: 0.80
chroma_suppress_strength: 1.0
suppress_raw_lo: 0.85
suppress_raw_hi: 0.98
cross_check:
enabled: true
model_name: ZhengPeng7/BiRefNet_HR-matting
input_size: 2048
reuse_as_seg: false
precision: bf16
proj_min: 3.0
l_min: 45.0
feather_sigma: 2.0
gate_lo: 0.70
gate_hi: 0.95
# Complex-background (non-flat) mode only: no hue-defined suspect zone, so the
# veto requires the second opinion itself to be confidently near-empty -- full
# strength at/below second_lo, fading to none at/above second_hi.
second_lo: 0.15
second_hi: 0.40
foreground:
enabled: true
method: ml
ml_regularization: 0.00001
despill:
enabled: false
server:
# Request concurrency (HTTP service only). cpu_workers = thread-pool size: >1 runs
# several requests at once, overlapping their CPU stages while the GPU forwards
# stay serialized -- keeps the GPU fed. gpu_concurrency = how many forwards may
# co-schedule on the SMs at once: 2 lifts GPU-bound throughput (batch-1 underfills
# the SMs) but roughly DOUBLES GPU activation memory.
# * On a >=24 GB card (e.g. 4080 SUPER 32 GB): gpu_concurrency: 2 peaks ~19 GB.
# * On a <=16 GB card: keep gpu_concurrency: 1 or it will OOM at 2048 cross-check.
# Env vars BGFILTER_CPU_WORKERS / BGFILTER_GPU_CONCURRENCY override these per box.
cpu_workers: 8
gpu_concurrency: 2