https://flyte.org logo
#hacktoberfest-2022
Title
# hacktoberfest-2022
c

cryptic

10/28/2022, 10:25 AM
@Samhita Alla I have one last question, how do I fix lint errors on
make lint
? I'm sorry but I'm not quite sure about it (https://github.com/flyteorg/flytekit/actions/runs/3326738618/jobs/5511140308#step:6:360)
s

Samhita Alla

10/28/2022, 10:26 AM
Can you
pre-commit install
in your flytekit repo locally? That should automatically warn you about lint errors during the commit.
c

cryptic

10/28/2022, 10:36 AM
It's little weird as I get the shellcheck result as failed on my local repo, but they completed successfully on GA
s

Samhita Alla

10/28/2022, 11:14 AM
Oh. So are you still seeing the error?
c

cryptic

10/28/2022, 12:29 PM
Copy code
def test_to_python_value_and_literal(transformer, python_type, format, python_val):
        ctx = context_manager.FlyteContext.current_context()
        tf = transformer
        lt = tf.get_literal_type(python_type)

        lv = tf.to_literal(ctx, python_val, type(python_val), lt)  # type: ignore
>       assert lv.scalar.blob.metadata == BlobMetadata(
            type=BlobType(
                format=format,
                dimensionality=BlobType.BlobDimensionality.SINGLE,
            )
        )
E       AttributeError: 'NoneType' object has no attribute 'blob'
lv.scalar is returning none it seems
s

Samhita Alla

10/28/2022, 12:48 PM
Can you share with me your pytest args?
Not this, the function. The whole function.
c

cryptic

10/28/2022, 12:53 PM
you mean the
test_to_python_value_and_literal
?
s

Samhita Alla

10/28/2022, 12:54 PM
Yes.
c

cryptic

10/28/2022, 12:54 PM
Copy code
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])

result_tensor = tf.matmul(a, b)

@pytest.mark.parametrize(
    "transformer,python_type,format,python_val",
    [
        (
            TensorFlowTensorTransformer(),
            tf.Tensor,
            TensorFlowTensorTransformer.TENSORFLOW_FORMAT,
            result_tensor,
        )
    ],
)

def test_to_python_value_and_literal(transformer, python_type, format, python_val):
    ctx = context_manager.FlyteContext.current_context()
    tf = transformer
    lt = tf.get_literal_type(python_type)

    lv = tf.to_literal(ctx, python_val, type(python_val), lt)  # type: ignore
    assert lv.scalar.blob.metadata == BlobMetadata(
        type=BlobType(
            format=format,
            dimensionality=BlobType.BlobDimensionality.SINGLE,
        )
    )
    assert lv.scalar.blob.uri is not None
    output = tf.to_python_value(ctx, lv, python_val, python_type)
    assert (output.numpy() == python_val.numpy()).all()
s

Samhita Alla

10/28/2022, 12:56 PM
What’s your
to_literal
?
c

cryptic

10/28/2022, 12:57 PM
Copy code
def to_literal(
        self,
        ctx: FlyteContext,
        python_val: tf.Tensor,
        python_type: Type[tf.Tensor],
        expected: LiteralType,
    ) -> Literal:
        meta = BlobMetadata(
            type=_core_types.BlobType(
                format=self.TENSORFLOW_FORMAT,
                dimensionality=_core_types.BlobType.BlobDimensionality.SINGLE,
            )
        )

        local_path = ctx.file_access.get_random_local_path()
        #pathlib.Path(local_path).parent.mkdir(parents=True, exist_ok=True)

        # Save the `tf.tensor` as a file on disk
        #global local_file_path
        local_path = os.path.join(local_path, "tensor_data")
        tf.io.write_file(local_path, tf.io.serialize_tensor(python_val))

        tensor_dtype = python_val.dtype.name

        remote_path = ctx.file_access.get_random_remote_path(local_path)
        ctx.file_access.put_data(local_path, remote_path, is_multipart=False)
        return Literal(
        collection=LiteralCollection(
            literals=[
                Literal(scalar=Scalar(blob=Blob(metadata=meta, uri=remote_path))),
                Literal(scalar=Scalar(primitive=Primitive(string_value=tensor_dtype))),
            ]
        )
    )
s

Samhita Alla

10/28/2022, 12:58 PM
It’s a LiteralCollection, right? So you’ll need to change your test. Your test is for Blob.
c

cryptic

10/28/2022, 12:59 PM
Oops, let me change
77 Views