Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python code block to workflows #509

Merged
merged 19 commits into from
Jul 18, 2024

Conversation

PawelPeczek-Roboflow
Copy link
Collaborator

@PawelPeczek-Roboflow PawelPeczek-Roboflow commented Jul 8, 2024

Description

This is the preview of custom python code block in workflows - so far implemented quite ugly - but showcasing what will be possible.

Methodology:

  • new optional entry in workflow definition with dynamic blocks
  • dynamic blocks configurable via JSON definition (manifest + code)
  • once compiled - dynamic block becomes standard block with minor limitations (no init parameters from EE, but possible to define init() function to define state)
  • dynamic blocks can be instantiated as any other block in "steps" list
  • proven with tests that steps works nicely with other blocks, including flow-control
  • disabled completely at hosted platform (proven by tests) - both compilation and execution!
  • new endpoint POST /workflows/blocks/describe which takes optional payload with list of blocks - once it is done -dynamic blocks schemas and connections are generated into output -
  • old, parameter-free GET /workflows/blocks/describe remained, yet deprecated to be removed later
  • GET /workflows/blocks/describe and POST /workflows/blocks/describe will return OpenAPI schema for manifest of dynamic block

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this change been tested, please provide a testcase or example of how you tested the change?

  • Old CI still green 🟢
  • new unit tests
  • new integration tests (workflows, hosted-inference, inference sever)

Any specific deployment considerations

  • POST endpoint for workflows must be exposed by gateway (already submitted infra PR)

Docs

  • Docs updated? What were the changes:

Copy link
Contributor

@yeldarby yeldarby left a comment

Choose a reason for hiding this comment

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

This looks pretty epic.

WorkflowBlockManifest,
)

IMPORTS_LINES = [
Copy link
Contributor

Choose a reason for hiding this comment

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

If your custom code block needs other available dependencies (eg time, json, os, requests, cv2, shapely, our CLIP Model, etc) is there a way to add them to the import list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

one may import more in the string with python code, like:

import cv2
# any other import 

def function(x, y, z):
    pass

we could also extend the imports, yet for instance CLIP should probably be used via model manager as manual init in multiple blocks may end up OOM on multiple instances on the same model. We can obviously add more imports which I will do, the question is what we suggest people regarding model usage - I believe it would be better to suggest using models within existing blocks if possible and only use model in-place when there is no other option

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, added separate field in manifest to declare optional imports - that is going to give us more visibility

description="Definition of manifest for dynamic block to be created in runtime by "
"workflows execution engine."
)
code: PythonCode = Field(
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably also needs an init function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 changed the way how it will work to have init function and run function with self injected as first param which would have access to self._init_results

description="Accepted dimensionality offset for parameter. Dimensionality works the same as for "
"traditional workflows blocks.",
)
selector_types: List[SelectorType] = Field(
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you accept an image (whether it be an output of a previous step or an input to the workflow)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

u choose union of

class SelectorType(Enum):
    INPUT_IMAGE = "input_image"
    INPUT_PARAMETER = "input_parameter"
    STEP_OUTPUT = "step_output"

which is almost 1-1 mapping to types: WorkflowImageSelector, WorkflowParameterSelector, StepOutputSelector

Copy link
Contributor

@yeldarby yeldarby left a comment

Choose a reason for hiding this comment

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

This looks good to me 🔥

(but going to wait for someone else to give the official ✅)

hansent
hansent previously approved these changes Jul 18, 2024
Copy link
Contributor

@hansent hansent left a comment

Choose a reason for hiding this comment

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

lgtm, discussed/reviewed on tuple/zoom

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably the file name should be test_dimension_collapse.py

@PawelPeczek-Roboflow PawelPeczek-Roboflow merged commit fd7fe31 into main Jul 18, 2024
58 checks passed
@PawelPeczek-Roboflow PawelPeczek-Roboflow deleted the feature/add_python_code_block branch July 18, 2024 15:51
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.

4 participants