MCPcopy
hub / github.com/dmlc/dgl / deserialize_from_payload

Function deserialize_from_payload

python/dgl/distributed/rpc.py:519–556  ·  view source on GitHub ↗

Deserialize and reconstruct the object from payload. The object must have implemented the __setstate__ function. Parameters ---------- cls : class The object class. data : bytearray Serialized data buffer. tensors : list[Tensor] A list of tensor payl

(cls, data, tensors)

Source from the content-addressed store, hash-verified

517
518
519def deserialize_from_payload(cls, data, tensors):
520 """Deserialize and reconstruct the object from payload.
521
522 The object must have implemented the __setstate__ function.
523
524 Parameters
525 ----------
526 cls : class
527 The object class.
528 data : bytearray
529 Serialized data buffer.
530 tensors : list[Tensor]
531 A list of tensor payloads.
532
533 Returns
534 -------
535 object
536 De-serialized object of class cls.
537 """
538 pos, nonarray_state = pickle.loads(data)
539 # Use _PLACEHOLDER to distinguish with other deserizliaed elements
540 state = [_PLACEHOLDER] * (len(nonarray_state) + len(tensors))
541 for i, no_state in zip(pos, nonarray_state):
542 state[i] = no_state
543 if len(tensors) != 0:
544 j = 0
545 state_len = len(state)
546 for i in range(state_len):
547 if state[i] is _PLACEHOLDER:
548 state[i] = tensors[j]
549 j += 1
550 if len(state) == 1:
551 state = state[0]
552 else:
553 state = tuple(state)
554 obj = cls.__new__(cls)
555 obj.__setstate__(state)
556 return obj
557
558
559@register_object("rpc.RPCMessage")

Callers 5

test_serializeFunction · 0.90
recv_requestFunction · 0.85
recv_responseFunction · 0.85
remote_callFunction · 0.85
recv_responsesFunction · 0.85

Calls 2

__new__Method · 0.45
__setstate__Method · 0.45

Tested by 1

test_serializeFunction · 0.72