feat: Rename predict to run with backward compatibility#3015
feat: Rename predict to run with backward compatibility#3015markphelps wants to merge 10 commits into
Conversation
|
I found a bug in the backward compatibility delegation logic in I posted a review with a suggested fix using the existing |
There was a problem hiding this comment.
I found one critical bug in the backward compatibility delegation logic that needs to be fixed before this can be merged. The delegation bridge in python/cog/predictor.py doesn't work correctly for user classes that only override predict().
The issue is that the condition checks if "predict" is in the class __dict__ but "run" is not. However, since BaseRunner defines run(), both methods will be in the class __dict__, so the fallback never triggers.
I've provided a suggestion with the fix using the existing _user_method_owner() helper.
|
Posted the review comment. The critical issue is the backward compatibility delegation in |
|
LGTM |
|
Based on my thorough review of this PR, I can see that:
This PR successfully renames LGTM |
|
@copilot resolve the merge conflicts in this pull request |
Rename the user-facing predict concept to run across the entire stack: - CLI: cog predict → cog run (predict kept as deprecated alias) - Python SDK: BasePredictor → BaseRunner, predict() → run() - Config: predict: → run: in cog.yaml - Examples: predict.py → run.py, Predictor → Runner Backward compatibility maintained throughout: - cog predict still works with deprecation warning - BasePredictor kept as alias for BaseRunner - predict() method still works - predict: in cog.yaml still accepted Also includes: - Doctor check with auto-migration for common patterns - Integration tests for both legacy and new interfaces - Updated documentation and examples
2478693 to
6a2477d
Compare
|
Based on my thorough review of PR #3015, I can confirm:
LGTM |
|
LGTM |
- Add deprecation warning to BaseRunner.predict() bridge - Rename _validate_predict to _validate_run_or_predict for clarity - Add BaseRunner core feature tests (setup, weights, stateful, multiple inputs) - Add run() tests for complex types in inspector tests - Add predict_legacy_predictor integration test for common migration path - Add doctor_predict_to_run_collision test for file conflict handling - Add run_legacy_async_predictor integration test - Verify cog init template uses BaseRunner/run() in integration tests - Add Rust test for BasePredictor inheritance - Fix documentation terminology (predictor→runner, predict function→run function)
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR. This PR renames predict to run across the entire stack while maintaining full backward compatibility.
All critical issues from previous reviews have been resolved:
- The backward compatibility delegation in
python/cog/predictor.py:71-74correctly uses_user_method_owner()to detect where methods are actually defined. - The unused import in
python/cog/_inspector.pyhas been cleaned up.
One minor issue remains:
| } | ||
|
|
||
| module := "" | ||
| var className string |
There was a problem hiding this comment.
Useless assignment to local variable. This definition of className is never used before being overwritten in all code paths.
| var className string | |
| module := "" | |
| var className string |
|
I've completed my review of PR #3015. The review has been posted to GitHub. Summary:
The PR successfully implements the |
- Fix Python formatting (ruff) - Regenerate docs/llms.txt to match updated docs - Fix doctor integration tests to expect non-zero exit code when issues found - Clean up variable declarations in pkg/schema/python/parser.go
|
LGTM |
|
|
||
| By default, cog doctor reports problems without modifying any files. | ||
| Pass --fix to automatically apply safe fixes.`, | ||
| Pass --fix to automatically apply safe fixes, including migrating deprecated predict names to run names when no file collision exists.`, |
There was a problem hiding this comment.
Love the idea of --fix, but seems out of place to call out one type of automatic fix it'll do.
| runDispatchExec | ||
| ) | ||
|
|
||
| func runDispatchModeForArgs(args []string) runDispatchMode { |
There was a problem hiding this comment.
IMO I think we can yank support for still using run to invoke exec. It's been deprecated with a warning for ~4-6 weeks now. The complexity of guessing isn't worth it and may have real negative side effects.
| "description": "Deprecated compatibility field for run. Use run instead." | ||
| }, | ||
| "train": { | ||
| "$id": "#/properties/train", |
There was a problem hiding this comment.
While you're here: the train field description just below (line 184) still says "The pointer to the Predictor object in your code, which defines how predictions are run on your model." -- that's the old predict description that was never updated. Should describe the training interface.
| } else { | ||
| instance.call_method(method_name, (), Some(&input_dict)) | ||
| } | ||
| .map_err(|e| PredictionError::Failed(format!("Failed to call predict: {}", e)))?; |
There was a problem hiding this comment.
This error message says "Failed to call predict" even when the method being invoked is run(). method_name is available here -- use it:
.map_err(|e| PredictionError::Failed(format!("Failed to call {method_name}: {e}")))?;| @@ -0,0 +1,17 @@ | |||
| cog build -t $TEST_IMAGE | |||
| stderr 'predict' | |||
There was a problem hiding this comment.
stderr 'predict' matches any line containing "predict" -- build log noise, image names, the filename itself, etc. This would pass even if the deprecation warning were missing. Assert the actual deprecation message text instead.
Same issue in run_legacy_predictor.txtar:2 and run_legacy_async_predictor.txtar:2.
| @@ -0,0 +1,16 @@ | |||
| # Build and run a new-style model | |||
| cog build -t $TEST_IMAGE | |||
| cog run $TEST_IMAGE -i s=world | |||
There was a problem hiding this comment.
The golden-path test for new-style Runner models should verify no deprecation noise appears. Add ! stderr 'deprecated' to make that explicit.
|
Based on my review of the current state of PR #3015, I can confirm: All critical issues from previous reviews have been resolved:
The PR successfully implements the LGTM |
|
Based on my review of the current state of PR #3015:
All critical issues from previous reviews have been resolved. The PR successfully implements the LGTM |
Summary
Renames the user-facing
predictconcept torunacross the entire stack while maintaining full backward compatibility.Changes
CLI
cog runcommand (replacescog predictas primary)cog predictkept as deprecated alias with warningcog runhandles both predictions and exec commandsPython SDK
BaseRunnerclass (replacesBasePredictor)run()method (replacespredict())BasePredictorkept as compatibility aliaspredict()still works via two-way delegation bridgeConfiguration
run:field incog.yaml(replacespredict:)predict:still accepted with deprecation warningcog doctor --fixcan auto-migrate common patternsExamples & Docs
predict.py→run.pyin examplesPredictor→Runnerin examplesTests
Backward Compatibility
All existing models continue to work without changes:
cog predict→ works with warningBasePredictor→ works with warningpredict()→ works with warningpredict:in cog.yaml → works with warning