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

[core] Ray prevents to set a write flag of numpy array. #13360

Closed
brorro opened this issue Jan 12, 2021 · 10 comments
Closed

[core] Ray prevents to set a write flag of numpy array. #13360

brorro opened this issue Jan 12, 2021 · 10 comments
Labels
question Just a question :)

Comments

@brorro
Copy link

brorro commented Jan 12, 2021

What is the problem?

I'm using ray==1.1.0, ubuntu==20.04 and pytorch==1.7.1.
When i try to set a flag of an array, numpy raises an exception,
ValueError: cannot set WRITEABLE flag to True of this array.
This happened after i got upgrade ray to 1.1.0 from 1.0.1.post1.
I needed to set write flag to make pytorch to construct tensors from the array, rather than copy and construct new tensor.

Reproduction (REQUIRED)

import numpy as np
import ray
import torch


@ray.remote(num_cpus=2, num_gpus=1)
class GPUActor:
    def __init__(self):
        pass

    def foo(self, client):
        client.data.setflags(write=True)
        tensor = torch.from_numpy(client.data)
        """
        Working on tensor
        """
        return tensor.sum().item()


class Client:
    def __init__(self):
        self.data = np.array([1, 2, 3])


ray.init(include_dashboard=False)


a = GPUActor.remote()
b = Client()
c = a.foo.remote(b)
d = ray.get(c)
print(d)

  • [YES] I have verified my script runs in a clean environment and reproduces the issue.
  • [YES] I have verified the issue also occurs with the latest wheels.
@brorro brorro added bug Something that is supposed to be working; but isn't triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Jan 12, 2021
@rkooo567
Copy link
Contributor

This is Ray's computation model (Objects in the store is immutable). cc @stephanie-wang Do you know any good way to get around this?

@krfricke
Copy link
Contributor

See also https://docs.ray.io/en/master/serialization.html#numpy-arrays
I don't think there's a workaround for that - you'll either have to construct and store the array on the actor or create a copy.

@krfricke krfricke added the core label Jan 13, 2021
@krfricke krfricke changed the title Ray prevents to set a write flag of numpy array. [core] Ray prevents to set a write flag of numpy array. Jan 13, 2021
@stephanie-wang stephanie-wang added question Just a question :) and removed bug Something that is supposed to be working; but isn't triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Jan 13, 2021
@stephanie-wang
Copy link
Contributor

Yes, the behavior is expected. The reason objects are immutable is to prevent possible inconsistencies with anyone else that has a reference to the same object (client in this case). If you want others to see the updates, you should wrap the Client() object in an actor, as @krfricke suggested. Otherwise, creating a copy should work.

@brorro
Copy link
Author

brorro commented Jan 14, 2021

It's so sad that I have to constantly copy large memory that will not be changed in whole life time. Wrapping the Client() in an actor is not an option because it has to be dynamically distributed to actors.

@brorro brorro closed this as completed Jan 14, 2021
@stephanie-wang
Copy link
Contributor

Hmm I think I misunderstood your original error. I didn't realize that the error was from setting the flag, not from writing directly to a read-only array. I'm not sure that this is a Ray error, actually. What numpy version are you using? There's a similar issue described here.

@brorro
Copy link
Author

brorro commented Jan 14, 2021

The version is 1.19.2 And yes you're right that the error occurs exactly when the flag is edited. I hope there is a way to handle this issue.

@stephanie-wang
Copy link
Contributor

stephanie-wang commented Jan 14, 2021 via email

@brorro
Copy link
Author

brorro commented Jan 14, 2021

numpy==1.15.4 resolved the issue, but it's too old to satisfy other packages' dependency.

@stephanie-wang
Copy link
Contributor

Okay, I'm closing this issue since it appears to be a problem with other libraries, not Ray. Good luck tracking this down!

@brorro
Copy link
Author

brorro commented Jan 14, 2021

I'm not sure this is related to other libraries, considering that previous Ray release just worked fine. The only thing I have changed was to upgrade Ray to 1.1.0. Anyway I have no choice but to stick with 1.0.1...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Just a question :)
Projects
None yet
Development

No branches or pull requests

4 participants