Skip to content

feat: Rename predict to run with backward compatibility#3015

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

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

Conversation

@markphelps
Copy link
Copy Markdown
Collaborator

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

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

@markphelps
Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

@copilot resolve the merge conflicts in this pull request

Resolved and pushed. The merge conflicts were fixed in f7a1887, with a small test cleanup follow-up in 2478693.

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
@markphelps markphelps force-pushed the rename-predict-run branch from 2478693 to 6a2477d Compare May 18, 2026 16:05
Comment thread pkg/schema/python/parser.go Fixed
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 18, 2026

Based on my thorough review of PR #3015, I can confirm:

  1. Critical bug fixed: The backward compatibility delegation 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. All components properly integrated:

    • CLI cog run command with smart dispatch (correctly routes to predict or exec)
    • Python SDK BaseRunner with two-way delegation bridge
    • Rust coglet method selection logic walking MRO correctly
    • Config validation handles both run and predict fields
    • Doctor migration tool with appropriate restrictions
  3. Test coverage comprehensive: Tests validate the delegation bridge works for classes that only override predict(), and integration tests cover both legacy and new interfaces.

  4. Previous issues resolved: The unused import in _inspector.py has been removed.

LGTM

github run

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 18, 2026

LGTM

github run

- 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)
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.

All critical issues from previous reviews have been resolved:

  1. The backward compatibility delegation in python/cog/predictor.py:71-74 correctly uses _user_method_owner() to detect where methods are actually defined.
  2. The unused import in python/cog/_inspector.py has been cleaned up.

One minor issue remains:

Comment thread pkg/schema/python/parser.go Outdated
}

module := ""
var className string
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Useless assignment to local variable. This definition of className is never used before being overwritten in all code paths.

Suggested change
var className string
module := ""
var className string

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 18, 2026

I've completed my review of PR #3015. The review has been posted to GitHub.

Summary:

  • The critical backward compatibility delegation bug identified in previous reviews has been properly fixed in python/cog/predictor.py:71-74
  • All major components are correctly implemented (CLI cog run, Python SDK BaseRunner, Rust coglet, doctor migration tool, config validation)
  • Test coverage is comprehensive
  • One minor code quality issue remains: an unused variable assignment in pkg/schema/python/parser.go:1332 which I've suggested a fix for

The PR successfully implements the predict to run rename across the entire stack while maintaining full backward compatibility.

github run

- 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
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 18, 2026

LGTM

github run

Comment thread pkg/cli/doctor.go Outdated

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.`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Love the idea of --fix, but seems out of place to call out one type of automatic fix it'll do.

Comment thread pkg/cli/run.go Outdated
runDispatchExec
)

func runDispatchModeForArgs(args []string) runDispatchMode {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread crates/coglet-python/src/predictor.rs Outdated
} else {
instance.call_method(method_name, (), Some(&input_dict))
}
.map_err(|e| PredictionError::Failed(format!("Failed to call predict: {}", e)))?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The golden-path test for new-style Runner models should verify no deprecation noise appears. Add ! stderr 'deprecated' to make that explicit.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 18, 2026

Based on my review of the current state of PR #3015, I can confirm:

All critical issues from previous reviews have been resolved:

  1. Backward compatibility delegation bug - Fixed in python/cog/predictor.py:71-74. The run() method now correctly uses _user_method_owner() to detect where methods are actually defined.

  2. Unused import - Fixed in python/cog/_inspector.py (no longer imports BaseRunner)

  3. Unused variable - Fixed in pkg/schema/python/parser.go (commit df040f3)

  4. Coglet error message - Fixed to use {method_name} variable instead of hardcoded "predict"

  5. Integration tests - Properly updated:

    • predict_legacy_predictor.txtar matches the specific deprecation warning
    • run_new_runner.txtar verifies no deprecation noise with ! stderr 'deprecated'
  6. Train field description - Fixed in config schema to say "training function"

The PR successfully implements the predict to run rename across the entire stack while maintaining full backward compatibility. All delegation logic works correctly, deprecation warnings are in place, and comprehensive tests cover both legacy and new interfaces.

LGTM

github run

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 18, 2026

Based on my review of the current state of PR #3015:

  1. Backward compatibility delegation bug - Fixed in python/cog/predictor.py:71-74. The run() method now correctly uses _user_method_owner() to detect where methods are actually defined.

  2. Unused import - Fixed in python/cog/_inspector.py (no longer imports BaseRunner)

  3. Unused variable - Fixed in pkg/schema/python/parser.go (commit df040f3)

  4. Coglet error message - Fixed to use {method_name} variable instead of hardcoded "predict"

  5. Integration tests - Properly updated with specific deprecation message assertions and negative assertions for new-style runners

  6. Train field description - Fixed in config schema to say "training function"

All critical issues from previous reviews have been resolved. The PR successfully implements the predict to run rename across the entire stack while maintaining full backward compatibility.

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.

3 participants