[Python] I get "TypeError: Attempting to call `get` on the value 0, which is not an...

Discussão em 'Python' iniciado por Stack, Novembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I used the following example code received from chatGPT when asking "error ObjectRef in ray.get after ray.put". The model suggested this code example should work, but it doesn't:

    import ray

    ray.init()

    # Store a large object in Ray
    data = [i for i in range(10**6)]
    data_ref = ray.put(data)

    # Define a task that uses the stored object
    @ray.remote
    def process_data(ref, start, end):
    data = ray.get(ref) # Retrieve the object
    return sum(data[start:end])

    # Launch parallel tasks using the ObjectRef
    tasks = [process_data.remote(data_ref, i * 100000, (i + 1) * 100000) for i in range(10)]
    results = ray.get(tasks) # Fetch results
    print(f"Total sum: {sum(results)}")


    I get the following error: TypeError: Attempting to call get on the value 0, which is not an ray.ObjectRef

    both print(type(data_def) and print(type(tasks[0]) give <class 'ray._raylet.ObjectRef'> but while ray.get(data_ref) gives an array of numbers ray.get(tasks[0]) produces the above mentioned error

    Continue reading...

Compartilhe esta Página