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

How to use Ray with closures? #7055

Open
mil-ad opened this issue Feb 4, 2020 · 2 comments
Open

How to use Ray with closures? #7055

mil-ad opened this issue Feb 4, 2020 · 2 comments
Labels
P3 Issue moderate in impact or severity question Just a question :)

Comments

@mil-ad
Copy link

mil-ad commented Feb 4, 2020

Is it possible to define a remote function through closures?

In the example below I want get_func and my_func to share the same resources (e.g. one GPU):

def get_func(a):

   a = a.to(torch.device("cuda")

    def my_func(e, f):
        return (e*f) + a

    return my_func

worker1 = get_func(10)
worker2 = get_func(20)

worker1(100)
worker2(100)

I think just decorating get_func won't be enough and I guess below won't work either?

@ray.remote(num_cpus=4, num_gpus=1)
def get_func(a):

   a = a.to(torch.device("cuda")

    @ray.remote(num_cpus=4, num_gpus=1)
    def my_func(e, f):
        return (e*f) + a

    return my_func

worker1 = get_func(10)
worker2 = get_func(20)

worker1(100)
worker2(100)
@mil-ad mil-ad added the question Just a question :) label Feb 4, 2020
@richardliaw
Copy link
Contributor

richardliaw commented Feb 6, 2020

Thanks for making this issue! Can you provide some more context about what you're trying to do (i.e., elaborating more about "making your functions share the same resources (e.g. one GPU)")?

@mil-ad
Copy link
Author

mil-ad commented Feb 8, 2020

So for example if you use something like Ignite with PyTorch, what you often do is construct trainer functions that are later called to actually do the training. It would be nice if the resource allocation could propagate from the trainer factory function to the actual trainer function.

@ericl ericl added the P3 Issue moderate in impact or severity label Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Issue moderate in impact or severity question Just a question :)
Projects
None yet
Development

No branches or pull requests

3 participants