[Bugfix] Fix local speculators with dots in the name from classifying as custom_class (#48754)
Signed-off-by: mgoin <mgoin64@gmail.com>
This commit is contained in:
@@ -626,6 +626,18 @@ class SpeculativeConfig:
|
||||
SpeculativeConfig._apply_composed_hf_override, target_hf_overrides
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _is_custom_proposer_path(model: str | None) -> bool:
|
||||
"""True if ``model`` is a dotted import path (e.g. ``pkg.MyProposer``)."""
|
||||
if model is None:
|
||||
return False
|
||||
if model.startswith(("http://", "https://", "file://")):
|
||||
return False
|
||||
if "/" in model:
|
||||
return False
|
||||
parts = model.split(".")
|
||||
return len(parts) >= 2 and all(part.isidentifier() for part in parts)
|
||||
|
||||
def __post_init__(self):
|
||||
# Note: "method" is a new parameter that helps to extend the
|
||||
# configuration of non-model-based proposers, and the "model" parameter
|
||||
@@ -636,14 +648,9 @@ class SpeculativeConfig:
|
||||
# default.
|
||||
|
||||
# infer method from user args
|
||||
# Check if the model field contains a custom module path (e.g., 'pkg.Mod')
|
||||
if (
|
||||
self.model is not None
|
||||
and "." in self.model
|
||||
and not self.model.startswith(("http://", "https://", "file://"))
|
||||
and "/" not in self.model # not a HuggingFace repo (org/model)
|
||||
if self.method is None and SpeculativeConfig._is_custom_proposer_path(
|
||||
self.model
|
||||
):
|
||||
# Treat as a custom class path
|
||||
self.method = "custom_class"
|
||||
elif self.method is None:
|
||||
if self.model in ("ngram", "[ngram]"):
|
||||
|
||||
Reference in New Issue
Block a user