Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ jobs:
name: "Test integration"
needs: build-python
runs-on: ubuntu-latest-16-cores
timeout-minutes: 20
timeout-minutes: 25
Copy link
Member

Choose a reason for hiding this comment

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

thanks!

steps:
- uses: actions/checkout@v4
with:
Expand Down
7 changes: 6 additions & 1 deletion pkg/cli/predict.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ func isURI(ref *openapi3.Schema) bool {
}

func predictIndividualInputs(predictor predict.Predictor, inputFlags []string, outputPath string, isTrain bool) error {
console.Info("Running prediction...")
if isTrain {
console.Info("Running training...")
} else {
console.Info("Running prediction...")
}

schema, err := predictor.GetSchema()
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build:
python_version: "3.12"
train: "train.py:Trainer"
predict: "predict.py:Predictor"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from cog import BasePredictor


class Predictor(BasePredictor):
def predict(self, s: str) -> str:
return "hello " + s
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from cog import BasePredictor


class Trainer(BasePredictor):
def setup(self) -> None:
print("Trainer is setting up.")

def train(self, s: str) -> str:
print("Trainer.train called.")
return "hello train " + s

def predict(self, s: str) -> str:
print("Trainer.predict called.")
return "hello predict " + s
17 changes: 17 additions & 0 deletions test-integration/test_integration/test_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,20 @@ def test_train_pydantic2(tmpdir_factory, cog_binary):
capture_output=True,
)
assert result.returncode == 0


def test_training_setup_project(tmpdir_factory, cog_binary):
project_dir = Path(__file__).parent / "fixtures/training-setup-project"
out_dir = pathlib.Path(tmpdir_factory.mktemp("project"))
shutil.copytree(project_dir, out_dir, dirs_exist_ok=True)
result = subprocess.run(
[cog_binary, "train", "--debug", "-i", "s=world"],
cwd=out_dir,
check=False,
capture_output=True,
text=True,
)
assert result.returncode == 0
assert "Trainer is setting up." in str(result.stderr)
with open(out_dir / "weights", "r", encoding="utf8") as f:
assert f.read() == "hello predict world"