File size: 1,230 Bytes
6c46b3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
use serde::{Serialize, Deserialize};
use bytes::Bytes;

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum TensorDataType {
    F32,
    F16,
    BF16,
    Q4K,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct SwarmTensor {
    pub dims: Vec<usize>,
    pub data_type: TensorDataType,
    pub data: Bytes, 
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct TensorPacket {
    pub task_id: String,
    pub sequence_id: u64,
    pub source_node: String,
    pub target_node: String,
    pub layer_range: (usize, usize),
    pub hidden_states: SwarmTensor,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum SwarmControlMessage {
    // Auth & Identity
    Hello { peer_id: String, backend: super::compute::BackendType },
    JoinResponse { encrypted_cluster_key: Vec<u8> },
    
    // Orchestration
    AssignLayers { start: usize, end: usize },
    StatusUpdate { load: f32, vram_usage: u64 },
    
    // Compute
    ForwardRequest(TensorPacket),
    ForwardResponse(TensorPacket),
    
    // Results
    StreamToken(String),
    TaskResult { 
        task_id: String, 
        logits: Vec<f32>, 
        output_state: Bytes 
    },
    
    // Control
    Heartbeat,
    DrainRequest,
}