mirror of
https://github.com/wassname/ray.git
synced 2026-08-03 13:10:57 +08:00
[tune] Remove hack to serve pin requests off thread (#2680)
* nopin * fix
This commit is contained in:
@@ -2,15 +2,12 @@ from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
from six.moves import queue
|
||||
import base64
|
||||
import numpy as np
|
||||
import threading
|
||||
|
||||
import ray
|
||||
|
||||
_pinned_objects = []
|
||||
_fetch_requests = queue.Queue()
|
||||
PINNED_OBJECT_PREFIX = "ray.tune.PinnedObject:"
|
||||
|
||||
|
||||
@@ -33,36 +30,11 @@ def get_pinned_object(pinned_id):
|
||||
|
||||
from ray.local_scheduler import ObjectID
|
||||
|
||||
if threading.current_thread().getName() != "MainThread":
|
||||
placeholder = queue.Queue()
|
||||
_fetch_requests.put((placeholder, pinned_id))
|
||||
print("Requesting main thread to fetch pinned object", pinned_id)
|
||||
return placeholder.get()
|
||||
|
||||
return _from_pinnable(
|
||||
ray.get(
|
||||
ObjectID(base64.b64decode(pinned_id[len(PINNED_OBJECT_PREFIX):]))))
|
||||
|
||||
|
||||
def _serve_get_pin_requests():
|
||||
"""This is hack to avoid ray.get() on the function runner thread.
|
||||
|
||||
The issue is that we run trainable functions on a separate thread,
|
||||
which cannot access Ray API methods. So instead, that thread puts the
|
||||
fetch in a queue that is periodically checked from the main thread.
|
||||
"""
|
||||
|
||||
assert threading.current_thread().getName() == "MainThread"
|
||||
|
||||
try:
|
||||
while not _fetch_requests.empty():
|
||||
(placeholder, pinned_id) = _fetch_requests.get_nowait()
|
||||
print("Fetching pinned object from main thread", pinned_id)
|
||||
placeholder.put(get_pinned_object(pinned_id))
|
||||
except queue.Empty:
|
||||
pass
|
||||
|
||||
|
||||
def _to_pinnable(obj):
|
||||
"""Converts obj to a form that can be pinned in object store memory.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user