fix: add ExperimentalFeatureWarning compat shim#2789
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a backwards-compatible ExperimentalFeatureWarning export to the Python cog SDK so older models that import it (to suppress warnings) don’t fail with ImportError after the coglet migration.
Changes:
- Introduces a lazy
ExperimentalFeatureWarningcompat shim via module-level__getattr__. - Emits a deprecation notice directly to stderr when the deprecated symbol is accessed.
- Exposes the deprecated symbol via
__all__.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ff8b338 to
f3156b0
Compare
Existing models import ExperimentalFeatureWarning to suppress warnings:
from cog import ExperimentalFeatureWarning
warnings.filterwarnings('ignore', category=ExperimentalFeatureWarning)
This class was removed when the Python HTTP server was replaced by
coglet, causing ImportError on model load.
The shim provides _ExperimentalFeatureWarning (a FutureWarning subclass)
via module-level __getattr__, which:
- Prints a deprecation notice to stderr (cannot be swallowed by
warnings.filterwarnings('ignore'))
- Caches in globals() so the message fires at most once
- Returns the class so existing filterwarnings() calls still work
Add Python unit tests verifying the __getattr__ compat shim works: import succeeds, deprecation prints to stderr once, is FutureWarning subclass, works with warnings.filterwarnings, unknown attrs raise. Add txtar integration test proving a predictor importing ExperimentalFeatureWarning builds and runs end-to-end. Also fix coglet wheel build/test workflow: - noxfile: fail loudly when dist/ has wheels but none match platform (was silently falling back to PyPI or installing wrong-platform wheel) - noxfile: always use editable install for SDK so tests run against working tree - mise.toml: remove sources/outputs caching from build:coglet:wheel (the broad glob falsely matched cross-compiled wheels, causing skips) - mise.toml: test:python depends on build:coglet:wheel so dist/ always has a native wheel
f3156b0 to
5fa03f4
Compare
Editable install fails in CI because setuptools_scm needs a full git checkout. Use the pre-built wheel from dist/ when available, fall back to editable install only for local dev.
meatballhat-cf
left a comment
There was a problem hiding this comment.
Looks like we got some wheel-related fixes along the way, which is 🎉 but also it would be nice for future selves if the PR description mentioned it.
| return self.model.generate(prompt, image) | ||
| """ | ||
|
|
||
| import sys as _sys |
There was a problem hiding this comment.
Why the _sys alias? To work around libraries that runtime patch stderr?
| # Metrics | ||
| "current_scope", | ||
| # Deprecated compat shims | ||
| "ExperimentalFeatureWarning", |
There was a problem hiding this comment.
I think ExperimentalFeatureWarning should not be in the __all__ since it's not supposed to be part of the public API. I found maybe one legit case of from cog import * in GitHub, so I think we can safely say the backward compatibility only applies to named access.
Summary
Existing models import
ExperimentalFeatureWarningfromcogto suppress experimental feature warnings. This was removed when the Python HTTP server was replaced by coglet (#2783), breaking those models at import time withImportError.What Changed
Added a backwards-compatible shim in
python/cog/__init__.pythat:ExperimentalFeatureWarningvia module__getattr__(lazy — only triggers when actually imported)warnings.filterwarnings("ignore")or any other warnings suppressionFutureWarningsubclass, so existingwarnings.filterwarnings("ignore", category=ExperimentalFeatureWarning)calls work syntacticallyModels affected
Any model that does:
Including
cog-examples/hello-concurrency,cog-examples/hello-context,cog-examples/hello-replicate.