Git Product home page Git Product logo

Comments (2)

welcome avatar welcome commented on September 28, 2024

Thank you for opening your first issue here! 🛠

from flyte.

runllm avatar runllm commented on September 28, 2024

The issue you're encountering with nested dynamic tasks not binding Pydantic models or dictionaries as inputs is a known problem. This is due to the way Flyte handles type transformations and bindings in dynamic workflows. Specifically, Flyte's type system and serialization mechanisms can struggle with complex types like Pydantic models and dictionaries when used in nested dynamic tasks.

Pydantic Model Issue

The error message for Pydantic models indicates a type mismatch:

[User] malformed dynamic workflow, caused by: Collected Errors: 10
	Error 0: Code: MismatchingBindings, Node Id: dn0, Description: Input [l] on node [dn0] expects bindings of type [simple:STRUCT].  Received []

This suggests that Flyte is expecting a STRUCT type but is not receiving the correct bindings.

Dictionary Issue

The error message for dictionaries indicates a NoneType issue:

TypeError: Failed to convert inputs of task 'flyte.workflows.test_wf.level2':
  'NoneType' object is not subscriptable

This suggests that the dictionary is not being correctly serialized or deserialized, leading to a NoneType being passed where a dictionary is expected.

Workaround

One potential workaround is to serialize the Pydantic model or dictionary to a JSON string before passing it to the nested dynamic task and then deserialize it within the task. This can help bypass the type transformation issues.

Here is an example of how you can modify your code to use JSON serialization:

Pydantic Model with JSON Serialization

from typing import List
from flytekit import dynamic, workflow
from pydantic.v1 import BaseModel
import json

class SModel(BaseModel):
    name: str

@dynamic
def level2(l: str) -> List[int]:
    model = SModel.parse_raw(l)
    return [1, 2, 3]

@dynamic
def level1(l: List[int]) -> str:
    v = []
    for i in l:
        v.append(level2(l=SModel(name="a").json()))
    return "test"

@workflow
def multi_wf(l: List[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) -> str:
    return level1(l=l)

Dictionary with JSON Serialization

from typing import List
from flytekit import dynamic, workflow
import json

@dynamic
def level2(l: str) -> List[int]:
    d = json.loads(l)
    return [1, 2, 3]

@dynamic
def level1(l: List[int]) -> str:
    v = []
    for i in l:
        v.append(level2(l=json.dumps({"name": "a"})))
    return "test"

@workflow
def multi_wf(l: List[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) -> str:
    return level1(l=l)

Would you like more details on this workaround or any other aspect of Flyte?

Sources:


This is an AI-generated response and your feedback is appreciated! Please leave a 👍 if this is helpful and 👎 if it is not.

Mention @RunLLM to ask follow-up questions. See runllm.com for more!

from flyte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.