-
Notifications
You must be signed in to change notification settings - Fork 0
/
multipart_basic.py
68 lines (50 loc) · 1.89 KB
/
multipart_basic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import ray
from typing import List, Any
#########################
# Basic Implementations #
#########################
@ray.remote
class Basic:
"""
Able to access the multipart object by index.
Downside: must download the entire multipart object on ray.get()
"""
def __init__(self, items: List[Any]):
self.items = items
def __getitem__(self, index: Any) -> Any:
return self.items[index]
@ray.remote
class RefBased:
"""
Does not require you to download the entire multipart object.
Downside: must generate one object ref per part.
# Note: does this even have any upside over the Basic implementation?
Doesn't the driver still need to track all the nested references?
"""
def __init__(self, items: List[Any]):
self.items = items
def __getitem__(self, index: Any) -> Any:
return self.items[index]
###############################################
# Advanced Implementation - API Brainstorming #
###############################################
class MultiPartObjectRef_ExplicitOffsets:
# API
def __init__(self, items: List[Any], offsets: List[int]):
# Problem: offsets is necessary to index into items array,
# but how is the user going to know byte offsets? Also,
# user might want to use items like a dictionary (i.e. with)
# non-integer indices
self.offsets = offsets
self.items = items
def __getitem__(self, index: Any) -> Any:
return self.items[index]
class MultiPartObjectRef_ImplicitOffsets:
# API
def __init__(self, items: List[Any]):
# No offsets passed in --> need to be calculated somewhere on the
# backend. If items uses non-integer indices, the mapping should also
# be stored somewhere on the backend.
self.items = items
def __getitem__(self, index: Any) -> Any:
return self.items[index]