Reference for the technical implementation of the
comms.Mapper project code.
Mapper
Bases: RedisComm
Mapper Scarlet maps keys to values. Values could be anything such as model parameters, arrays etc. This Mapper inherits from multiple classes. However, at run time depending on the mode of the scarlet declaration, the classes are initialized.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
A unique string used to identify edge device |
Methods
-
refresh()refresh contract details -
_registerNewKey(key)registers new key by calling the corresponding underlying contract function -
Map(modelLocal,key)maps model parameters to a given key -
AllGather(modelLocal)Performs an AllGather operation in which all the key-value pairs are obtained. -
Reduce(modelLocal,op)Performs a Reduce operation which comprises of an AllGather followed by an operation on all the values obtained thus far. -
resetAll(modelLocal)Resets all the key-value pairs
Source code in comms/Mapper.py
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 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 | |
AllGather(modelLocal)
Performs an AllGather operation in which all the key-value pairs are obtained from the decentralized infrastructure.
Attributes:
| Name | Type | Description |
|---|---|---|
modelLocal |
numpy array
|
the content concerning modelLocal |
Returns:
| Name | Type | Description |
|---|---|---|
allgather_dict |
dict
|
the dictionary containing all key value pairs |
status : boolean status of the Map operation
exception : Exception exception if any else it will be None
Source code in comms/Mapper.py
137 138 139 140 141 142 143 144 145 146 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 | |
Map(modelLocal, key)
maps model parameters to a given key
Attributes:
| Name | Type | Description |
|---|---|---|
modelLocal |
numpy array
|
the content concerning modelLocal |
key : string value of key to be registered
Returns:
| Name | Type | Description |
|---|---|---|
successChunksList |
list
|
concerns the chunks which were successfully mapped |
status : boolean status of the Map operation
exception : Exception exception if any else it will be None
Source code in comms/Mapper.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
Reduce(modelLocal, op)
Performs a Reduce operation which comprises of an AllGather followed by an operation on all the values obtained thus far. The choice of operations is SUM,MAX,MIN,MULT. In case of MAX,MIN and MULT it will be an element wise operation.
Attributes:
| Name | Type | Description |
|---|---|---|
modelLocal |
numpy array
|
the content concerning modelLocal |
op : operation any one of the 4 operations SUM,MAX,MIN,MULT
Returns:
| Name | Type | Description |
|---|---|---|
sumV |
numpy array
|
final value after carrying out the operation sequentially on all values. |
status : boolean status of the Map operation
exception : Exception exception if any else it will be None
Source code in comms/Mapper.py
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 | |
performOperation(modelLocal, globalModel, operation)
performs the given operation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modelLocal |
numpy array
|
Argument 1 of the operation |
required |
globalModel |
numpy array
|
Argument 2 of the operation |
required |
Returns |
required | ||
retval |
return value is None if the operation is not supported, else it returns the result
|
required |
Source code in comms/Mapper.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
refresh()
refresh contract details
Source code in comms/Mapper.py
80 81 82 83 84 85 86 87 | |
resetAll(modelLocal)
Resets all the key-value pairs
Attributes:
| Name | Type | Description |
|---|---|---|
modelLocal |
numpy array
|
the content concerning modelLocal |
Returns:
| Name | Type | Description |
|---|---|---|
successChunksList |
list
|
concerns the chunks which were successfully reset |
exception : Exception exception if any else it will be None
Source code in comms/Mapper.py
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 | |