TransferQueue 0.1.3.dev5__py3-none-any.whl → 0.1.4.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,110 @@
1
+ import zmq
2
+ import time
3
+ import torch
4
+ from tensordict import TensorDict
5
+ from transfer_queue.utils.zmq_utils import ZMQMessage, ZMQRequestType
6
+ from tensordict.tensorclass import NonTensorData
7
+ import random
8
+ import multiprocessing
9
+
10
+
11
+
12
+ # -------------------------- Server(ROUTER Socket) --------------------------
13
+ def router_server():
14
+ context = zmq.Context()
15
+ router_socket = context.socket(zmq.ROUTER)
16
+ router_socket.bind("tcp://127.0.0.1:5555")
17
+ print("ROUTER Server is ready, binding:tcp://127.0.0.1:5555")
18
+
19
+
20
+ print("\n=== start communication(send_multipart/recv_multipart)===")
21
+ messages = router_socket.recv_multipart()
22
+ id = messages.pop(0)
23
+ response_msg = ZMQMessage.deserialize(messages)
24
+ print(response_msg)
25
+
26
+ # Try to do in-place modification to see if it's allowed
27
+ td = response_msg.body['data']
28
+ print(f"Server解析数据::\n{td['strided']},\n{td['jagged']},\n{td['empty_tensor']},\n{td['nested']},\n{td['non_contiguous']}")
29
+ print(f"Server连续性:{td['non_contiguous'].is_contiguous()}")
30
+ # it's safe to do in-place modification even we set
31
+ # arr = torch.frombuffer(buffer, dtype=torch.uint8)
32
+
33
+ print(f"Server指针{td['strided'].data_ptr()}, {td['jagged'].data_ptr()}, {td['empty_tensor'].data_ptr()}, "
34
+ f"{td['nested'].data_ptr()}, {td['non_contiguous'].data_ptr()}")
35
+ router_socket.send_multipart([
36
+ id,
37
+ b"ack",
38
+ ])
39
+
40
+
41
+ time.sleep(1)
42
+ router_socket.close()
43
+ context.term()
44
+
45
+ # -------------------------- Client(DEALER Socket) --------------------------
46
+ def dealer_client():
47
+ context = zmq.Context()
48
+ dealer_socket = context.socket(zmq.DEALER)
49
+ # set client identity
50
+ dealer_socket.setsockopt_string(zmq.IDENTITY, "client_001")
51
+ dealer_socket.connect("tcp://127.0.0.1:5555")
52
+ print("DEALER Client is ready, connecting:tcp://127.0.0.1:5555")
53
+ time.sleep(0.5)
54
+
55
+ base = torch.randn(2, 10)
56
+ non_contiguous = base[:, ::2]
57
+ print(f"Client非连续张量连续性:{non_contiguous.is_contiguous()}")
58
+
59
+ # Create TensorDict with different layouts
60
+ td = TensorDict(
61
+ {
62
+ "strided": torch.randn(2, 5, 3),
63
+ "jagged": torch.nested.as_nested_tensor([torch.randn(3, 4), torch.randn(2, 4)], layout=torch.jagged),
64
+ "empty_tensor": torch.empty(2, 0),
65
+ "nested": torch.nested.as_nested_tensor([torch.randn(4, 3), torch.randn(2, 4)], layout=torch.strided),
66
+ "non_contiguous": non_contiguous,
67
+ },
68
+ batch_size=2,
69
+ )
70
+ print(f"Client原始数据:\n{td['strided']},\n{td['jagged']},\n{td['empty_tensor']},\n{td['nested']},\n{td['non_contiguous']}")
71
+ print(f"Client连续性:{td['non_contiguous'].is_contiguous()}")
72
+ # 打印原始数据的指针位置
73
+
74
+ print(f"Client指针{td['strided'].data_ptr()}, {td['jagged'].data_ptr()}, {td['empty_tensor'].data_ptr()}, "
75
+ f"{td['nested'].data_ptr()}, {td['non_contiguous'].data_ptr()}")
76
+
77
+
78
+ request_msg = ZMQMessage.create(
79
+ request_type=ZMQRequestType.PUT_DATA,
80
+ sender_id='123',
81
+ receiver_id='456',
82
+ body={"data":td},
83
+ )
84
+
85
+
86
+ dealer_socket.send_multipart(request_msg.serialize(),copy=False)
87
+
88
+
89
+ response_frames = dealer_socket.recv_multipart()
90
+ response_frame1 = response_frames[0]
91
+ print(f"DEALER Receive → Frame: {response_frame1}")
92
+
93
+ dealer_socket.close()
94
+ context.term()
95
+
96
+ # -------------------------- Start all processes --------------------------
97
+ if __name__ == "__main__":
98
+ # Start server process
99
+ server_process = multiprocessing.Process(target=router_server)
100
+ server_process.start()
101
+ time.sleep(0.5)
102
+
103
+ # Start client process
104
+ client_process = multiprocessing.Process(target=dealer_client)
105
+ client_process.start()
106
+
107
+
108
+ server_process.join()
109
+ client_process.join()
110
+ print("Test Finish!")
@@ -1,3 +1,17 @@
1
+ # Copyright 2025 The TransferQueue Team
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  import logging
2
16
  import os
3
17
  import sys
@@ -1,14 +1,30 @@
1
+ # Copyright 2025 The TransferQueue Team
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import sys
1
16
  import unittest
17
+ from pathlib import Path
2
18
 
3
19
  import torch
4
20
  from tensordict import TensorDict
5
21
 
6
- from transfer_queue.metadata import (
7
- BatchMeta,
8
- FieldMeta,
9
- SampleMeta,
10
- )
11
- from transfer_queue.storage.managers.base import KVStorageManager
22
+ # Setup path
23
+ parent_dir = Path(__file__).resolve().parent.parent
24
+ sys.path.append(str(parent_dir))
25
+
26
+ from transfer_queue.metadata import BatchMeta, FieldMeta, SampleMeta # noqa: E402
27
+ from transfer_queue.storage.managers.base import KVStorageManager # noqa: E402
12
28
 
13
29
 
14
30
  class Test(unittest.TestCase):