sgl-project/sglang · error · ValueError

func_path should contain both module name and func name…

Error message

func_path should contain both module name and func name (such as 'module.func')

What it means

Dynamic-function loader validation: the func_path string must contain both module and function names in 'module.func' dotted form (e.g. 'my_pkg.my_module.my_func'). A path without a dot (or with too few segments) is rejected.

Solutions

  1. Use fully qualified 'package.module.func' form
  2. Validate the config string contains a '.' before passing
  3. Default the config to a shipped fully-qualified function

Example fix

# before
fn = dynamic_import("eplb")
# after
fn = dynamic_import("sglang.srt.eplb.eplb_manager")
Defensive patterns

Strategy: validation

Validate before calling

assert "." in func_path and len(func_path.split(".")) >= 2

Type guard

def is_qualified_path(s: str) -> bool:
    return isinstance(s, str) and s.count(".") >= 1 and all(s.split("."))

Prevention

When it happens

Trigger: Passing 'mymodel', 'run', or '' to dynamic_import — any string without a '.' separator.

Common situations: Config strings for pluggable attention/workload functions where the user forgot the module qualifier, or an empty default leaked through.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/14340d636882e6eb. Report an issue: GitHub.

Appendix: source

Thrown at python/sglang/srt/utils/common.py:3971

    def __getitem__(self, key):
        return self.value[key]

    def __setitem__(self, key, value):
        self.value[key] = value

    @property
    def value(self):
        if self._creator is not None:
            self._value = self._creator()
            self._creator = None
        return self._value


def dynamic_import(func_path: str):
    parts = func_path.split(".")
    if len(parts) < 2:
        raise ValueError(
            "func_path should contain both module name and func name (such as 'module.func')"
        )
    module_path = ".".join(parts[:-1])
    func_name = parts[-1]
    module = importlib.import_module(module_path)
    func = getattr(module, func_name)
    return func


def gc_object_counts():
    import gc

    g0 = len(gc.get_objects(0))
    g1 = len(gc.get_objects(1))
    g2 = len(gc.get_objects(2))
    return g0, g1, g2

View on GitHub (pinned to 0132848349)