label-studio-ml-backend icon indicating copy to clipboard operation
label-studio-ml-backend copied to clipboard

BUG: kwargs configuration no longer passed to model initialization in WSGI files

Open WillieMaddox opened this issue 4 months ago • 1 comments

Problem Summary

Configuration parameters specified via --with flag or config.json file are not being passed to model initialization in *_wsgi.py files, breaking customization functionality that previously worked.

Expected Behavior

  • kwargs from --with flag should be passed to model constructor
  • kwargs from config.json should be passed to model constructor
  • Model should initialize with custom parameters as specified in configuration

Current Behavior

  • kwargs are loaded and parsed correctly
  • kwargs are only used during the --check validation step
  • kwargs are not passed to the actual model instance used by the web app
  • Model initializes with default parameters only

Steps to Reproduce

  1. Run any WSGI example with custom kwargs: python examples/yolo/_wsgi.py --with param=value
  2. Observe that the web app uses default model parameters

Code Analysis

In examples/yolo/_wsgi.py (and other WSGI files):

kwargs = get_kwargs_from_config()
if args.kwargs:
    kwargs.update(parse_kwargs())

if args.check:
    model = YOLO(**kwargs)  # ✅ kwargs used here
    
app = init_app(
    model_class=YOLO,           # ❌ kwargs not passed here
    basic_auth_user=args.basic_auth_user,
    basic_auth_pass=args.basic_auth_pass,
)

Root Cause

The init_app() function appears to have removed support for passing **kwargs to the model constructor, but the argument parsing logic was left intact, creating a misleading interface.

Questions

  1. Is this an intentional breaking change? Should kwargs support be removed entirely?
  2. Is there a new recommended way to pass model parameters other than environment variables?
  3. Should init_app() be updated to accept and forward kwargs to model initialization?

Proposed Solutions

Option A: Restore kwargs functionality

app = init_app(
    model_class=YOLO,
    model_kwargs=kwargs,  # Pass kwargs to init_app
    basic_auth_user=args.basic_auth_user,
    basic_auth_pass=args.basic_auth_pass,
)

Option B: Remove misleading argument parsing

  • Remove --with and --kwargs options if they're no longer supported
  • Update documentation to reflect current capabilities

Environment

  • Affected files: All *_wsgi.py files in examples/
  • Configuration methods: Both --with flag and config.json affected
  • Impact: High - breaks existing workflows that rely on model customization

Labels: bug, breaking-change, configuration, wsgi

WillieMaddox avatar Jun 19 '25 19:06 WillieMaddox