Hello, I'm trying to output a list of keras models...
# announcements
n
Hello, I'm trying to output a list of keras models from a solid, but those models require a custom serialization strategy. It appears to me that a list of elements is pickled together, as one, rather than using the serialization strategy associated with the inner type. Is that true? What's the best way to go about this? Do I make another dagster type, of kind list, that uses a custom serialization strategy? Here is a test for reference, attempting to show that the inner type's serialization strategy doesn't get used:
Copy code
import dill

from dagster import (
    InputDefinition,
    OutputDefinition,
    execute_solid,
    lambda_solid,
    SerializationStrategy,
    usable_as_dagster_type,
    List,
)

dilled = False

class DillSerializationStrategy(SerializationStrategy):
    """Dill it."""
    def __init__(self, name='dill'):
        super(DillSerializationStrategy, self).__init__(name)

    def serialize(self, value, write_file_obj):
        global dilled
        dilled = True
        dill.dump(value, write_file_obj)

    def deserialize(self, read_file_obj):
        return dill.load(read_file_obj)


@usable_as_dagster_type(
    serialization_strategy=DillSerializationStrategy(),
)
class SomeDagsterType:
    def __init__(self):
        x = 1


def test_serialization():
    @lambda_solid(
        name='ingest',
        input_defs=[
            InputDefinition(name='a', dagster_type=List[SomeDagsterType])
        ],
        output_def=OutputDefinition(name='result', dagster_type=List[SomeDagsterType]),
    )
    def ingest(a):
        return a

    result = execute_solid(
        solid_def=ingest,
        input_values={ 'a': [SomeDagsterType()] },
        environment_dict={
            'storage': {
                'filesystem': {},
            },
        },
    )

    v = result.output_value()
    assert dilled
m
Hi Noah, I believe this is actually an open issue (one of our oldest) -- https://github.com/dagster-io/dagster/issues/1190 -- very sorry you bumped into this but it's quite fixable and we can get you something that works in the next couple days
Thanks for the repro and I wonder if you wouldn't mind sharing the error message you got
n
Hi Max, here is the error message:
m
yikes, that leaves a lot to be desired
n
It seems like the 1 to 1 relationship between key and object is important, even if the object is a list of many elements. Then each key maps to one file. So all of the elements will be serialized using the serialization strategy associated with the inner type and then written into the same file. Is that true?
Curious what the solution is going to be. Thank you for replying quickly to this. A few days for a solution would be awesome, but no rush. I appreciate the help