-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * Debug logging * I/O * WIP * Debugging * WIP * Add debug logging * Update i/o * Startup improvements * Better error handling * Improve inputs * More debugging * Fix defaults * Fix empty URLs * Update array outputs * Update logging * Try adding saving of output files * Add debug logging * Don't use strict mimetypes * Try adding complex input types * Fix * Update up command * Cleanup * Refactor manager classes * Refactor up command * Make getting cog image name DRY * Update flake8 * Small refactor * Move utils * small refactor * remove comment * Handle object outputs * Add better error handling * Revert "Handle object outputs" This reverts commit 8847cd1. * Try to handle dict outputs * Try to handle dict outputs p2 * Update input description * populate env vars * Bump version * update cog wrapper image ref
- Loading branch information
Showing
16 changed files
with
819 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import subprocess | ||
from argparse import Namespace | ||
|
||
import yaml | ||
|
||
from pipeline.container import docker_templates | ||
from pipeline.util.frameworks import get_cog_image_name | ||
from pipeline.util.logging import _print | ||
|
||
from .schemas import PipelineConfig, PythonRuntime, RuntimeConfig | ||
|
||
|
||
def convert(namespace: Namespace) -> None: | ||
framework = namespace.type | ||
|
||
_print(f"Initializing new pipeline from {framework}...", "INFO") | ||
|
||
pipeline_name = getattr(namespace, "name", None) | ||
if not pipeline_name: | ||
pipeline_name = input("Enter a name for your pipeline: ") | ||
|
||
if framework == "cog": | ||
config = convert_cog(pipeline_name) | ||
else: | ||
raise NotImplementedError(f"Framework {framework} not supported") | ||
|
||
with open(getattr(namespace, "file", "./pipeline.yaml"), "w") as f: | ||
f.write(yaml.dump(config.dict(), sort_keys=False)) | ||
|
||
with open("./README.md", "w") as f: | ||
f.write(docker_templates.readme_template) | ||
|
||
_print(f"Successfully generated a new pipeline from {framework}.", "SUCCESS") | ||
_print( | ||
"Be sure to update the pipeline.yaml with the accelerators required by your " | ||
"pipeline", | ||
"WARNING", | ||
) | ||
|
||
|
||
def convert_cog(pipeline_name: str) -> PipelineConfig: | ||
|
||
# check cog command exists | ||
try: | ||
subprocess.run(["cog", "--version"], check=True, capture_output=True) | ||
except subprocess.CalledProcessError: | ||
_print( | ||
"cog not found, please install cog first: https://github.com/replicate/cog", | ||
"ERROR", | ||
) | ||
raise | ||
|
||
# build cog image | ||
# tag image with a standardised name | ||
cog_image_name = get_cog_image_name(pipeline_name) | ||
subprocess.run( | ||
["cog", "build", "-t", cog_image_name], | ||
check=True, | ||
# capture_output=True, | ||
) | ||
|
||
# Generate a pipeline config. Note that most of these fields will not be | ||
# used when wrapping a Cog pipeline | ||
config = PipelineConfig( | ||
# not used | ||
runtime=RuntimeConfig( | ||
container_commands=[], | ||
python=PythonRuntime( | ||
version="3.10", | ||
requirements=[], | ||
), | ||
), | ||
accelerators=[], | ||
# not used | ||
pipeline_graph="", | ||
pipeline_name=pipeline_name, | ||
accelerator_memory=None, | ||
# use a format which permits extra framework-specific options | ||
extras={"model_framework": {"framework": "cog", "save_output_files": False}}, | ||
readme="README.md", | ||
) | ||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.