Skip to content

Serialization of certain objects not handled correctly after 0.8.1 #7376

@mc-allen

Description

@mc-allen

What is the problem?

When using Ray 0.8.2 on Ubuntu 18.04, I am serializing data structures from the astropy library (https://pypi.org/project/astropy/ , version 4.0).

Previously, I have configured ray to use cloudpickle for many of these astropy types, as they couldn't be natively handled by ray/pyarrow. In 0.8.2 however, ray seems to be ignoring this configuration, and it converts the data type in question (astropy.constants.constant.Constant) to a numpy ndarray upon ray.put/ray.get, which is incorrect behavior and breaks downstream parts of my code.

Version 0.8.1 seems to be fine. I also reproduced the issue with the test cases below in ray-0.9.0.dev0 as of today.

I suspect that this is a bug related to classes that have numpy-related base class.

Reproduction (REQUIRED)

Case 1: ignoring custom serializer

import numpy
import ray

class MyConstant(numpy.ndarray):
    def __init__(self, value):
        super().__init__()
        self.constant = value
    
    def __str__(self):
        print(self.constant)

constant = MyConstant(123)

ray.shutdown()
ray.init()

def explode(x):
    raise RuntimeError()

ray.register_custom_serializer(type(constant), serializer=explode, deserializer=explode)

try:
    ray.put(constant)
    print('Should never get here!')
except (RuntimeError, IndexError):
    print('Correct behavior, proof that customer serializer was used.')

Case 2: Incorrect round-trip

import numpy
import ray

class MyConstant(numpy.ndarray):
    def __init__(self, value):
        super().__init__()
        self.constant = value
    
    def __str__(self):
        print(self.constant)

constant = MyConstant(123)

ray.shutdown()
ray.init()

ray.register_custom_serializer(type(constant), use_pickle=True)

repr_orig = repr(constant)
repr_ser =repr(ray.get(ray.put(constant)))

if repr_orig == repr_ser:
    print('Good round trip')
else:
    print('Bad round trip!')

print(repr_orig)
print(repr_ser)

If we cannot run your script, we cannot fix your issue.

  • I have verified my script runs in a clean environment and reproduces the issue.
  • I have verified the issue also occurs with the latest wheels.

Metadata

Metadata

Assignees

Labels

bugSomething that is supposed to be working; but isn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions