nos.common.shm
nos.common.shm ¶
SharedMemoryNumpyObject
dataclass
¶
Shared memory object wrapping numpy array.
Shared memory objects are updated with user-permissions (0666) under
/dev/shm/nos_psm_
Source code in nos/common/shm.py
mode
class-attribute
instance-attribute
¶
Shared memory mode
__repr__ ¶
__getstate__ ¶
Return the shared memory object state.
This method is called when the object is pickled (dumps).
__setstate__ ¶
Set the shared memory object state. This method is called when the object is unpickled (loads).
Parameters:
-
state
(Dict[str, Any]
) –Shared memory object state.
Source code in nos/common/shm.py
cleanup ¶
close ¶
Close the shared memory object (client-side / reader).
Source code in nos/common/shm.py
copy_from ¶
Copy data from the numpy array to shared memory object.
Source code in nos/common/shm.py
SharedMemoryDataDict ¶
Shared-memory data wrapper.
Source code in nos/common/shm.py
decode
staticmethod
¶
Decode the data dictionary with shared-memory references.
Note: First unpickle the data bytes, then replace the shared-memory references with numpy arrays. SharedMemoryNumpyObject have a custom getstate method that returns the shared-memory name, shape and dtype. The setstate method is called when the object is unpickled, and it creates a new SharedMemoryNumpyObject instance with the given name, shape and dtype.
Source code in nos/common/shm.py
encode
staticmethod
¶
SharedMemoryTransportManager
dataclass
¶
Shared memory transport manager.
Source code in nos/common/shm.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
__post_init__ ¶
__del__ ¶
create ¶
Create a shared memory segment for the data dictionary.
Note: The keys for shared memory segments are prefixed with the
namespace <client_id>/<object_id>/<key>
, while the objects_map
returned does not have the namespace prefixed (i.e.
Parameters:
-
data
(Dict[str, Any]
) –Inputs to the model ("images", "texts", "prompts" etc) as a dictionary of numpy arrays.
-
namespace
(str
, default:None
) –Unique namespace for the shared memory segment. Defaults to "".
Returns: Dict[str, Any]: Shared memory segment for the data dictionary.
Source code in nos/common/shm.py
cleanup ¶
Cleanup the shared memory segments.
Source code in nos/common/shm.py
copy
staticmethod
¶
Copy the data dict values to the shared memory segments for transport.
Parameters:
-
shm_map
(Dict[str, SharedMemoryNumpyObject]
) –Shared memory segments for the data dict values (destination).
-
data
(Dict[str, Any]
) –Inputs to the model ("images", "texts", "prompts" etc) as numpy arrays or lists of numpy arrays (src).
Returns: Dict[str, Any]: Shared memory segments for the data dict values.