Skip to content

feat: Rename predict to run with backward compatibility#3015

Open
markphelps wants to merge 4 commits into
mainfrom
rename-predict-run
Open

feat: Rename predict to run with backward compatibility#3015
markphelps wants to merge 4 commits into
mainfrom
rename-predict-run

Conversation

@markphelps
Copy link
Copy Markdown
Contributor

Summary

Renames the user-facing predict concept to run across the entire stack while maintaining full backward compatibility.

Changes

CLI

  • New cog run command (replaces cog predict as primary)
  • cog predict kept as deprecated alias with warning
  • Smart dispatch: cog run handles both predictions and exec commands

Python SDK

  • New BaseRunner class (replaces BasePredictor)
  • New run() method (replaces predict())
  • BasePredictor kept as compatibility alias
  • predict() still works via two-way delegation bridge

Configuration

  • New run: field in cog.yaml (replaces predict:)
  • predict: still accepted with deprecation warning
  • cog doctor --fix can auto-migrate common patterns

Examples & Docs

  • predict.pyrun.py in examples
  • PredictorRunner in examples
  • README.md, docs, architecture docs updated

Tests

  • Integration tests for both legacy and new interfaces
  • Doctor migration tests
  • Deprecation warning tests

Backward Compatibility

All existing models continue to work without changes:

  • cog predict → works with warning
  • BasePredictor → works with warning
  • predict() → works with warning
  • predict: in cog.yaml → works with warning

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
Comment thread python/tests/test_predictor.py Fixed
Comment thread python/cog/_inspector.py Fixed
Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread python/cog/predictor.py Outdated
Comment thread pkg/doctor/check_predict_to_run_migration.go Outdated
Comment thread pkg/schema/python/parser.go
Comment thread python/cog/__init__.py
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 12, 2026

I found a bug in the backward compatibility delegation logic in python/cog/predictor.py. The condition on line 76 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__ when a user only overrides predict(), so the fallback to self.predict(**kwargs) will never trigger.

I posted a review with a suggested fix using the existing _user_method_owner() helper function which correctly walks the MRO to find where methods are actually defined.

github run

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread python/cog/predictor.py
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 12, 2026

Posted the review comment. The critical issue is the backward compatibility delegation in python/cog/predictor.py line 76 - it needs to use _user_method_owner() to correctly detect when a user class only overrides predict().

github run

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 12, 2026

LGTM

github run

@markphelps markphelps marked this pull request as ready for review May 13, 2026 13:58
@markphelps markphelps requested a review from a team as a code owner May 13, 2026 13:58
@markphelps markphelps requested a review from michaeldwan May 13, 2026 13:59
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 13, 2026

Based on my thorough review of this PR, I can see that:

  1. The critical bug has been fixed: The backward compatibility delegation logic in python/cog/predictor.py:71-74 now correctly uses _user_method_owner() to detect where methods are actually defined, rather than checking __dict__ directly.

  2. Tests are comprehensive: The test file includes tests for the delegation bridge (test_base_runner_run_delegates_to_legacy_predict_with_positional_args) which validates that users who only override predict() will have their method called via the run() delegation.

  3. All components are properly integrated:

    • CLI cog run command with smart dispatch
    • Rust coglet method selection logic
    • Config validation for both run and predict fields
    • Doctor migration tool with appropriate restrictions
  4. The import issue mentioned in previous reviews (BaseRunner import in _inspector.py) appears to have been resolved - the current import is from .predictor import BasePredictor, _user_method_owner which doesn't include the unused BaseRunner.

This PR successfully renames predict to run across the entire stack while maintaining full backward compatibility. The delegation bridge works correctly, deprecation warnings are in place, and the migration tool handles common cases.

LGTM

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant