* Await the values of all losses and metrics.
()
| 314 | * Await the values of all losses and metrics. |
| 315 | */ |
| 316 | async syncData() { |
| 317 | const promises: Array<Promise<Float32Array|Int32Array|Uint8Array>> = []; |
| 318 | const keys: string[] = []; |
| 319 | const indices: number[] = []; |
| 320 | for (const key in this.history) { |
| 321 | const valueArray = this.history[key]; |
| 322 | for (let i = 0; i < valueArray.length; ++i) { |
| 323 | if (typeof valueArray[i] !== 'number') { |
| 324 | const valueScalar = valueArray[i] as Tensor; |
| 325 | promises.push(valueScalar.data()); |
| 326 | keys.push(key); |
| 327 | indices.push(i); |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | const values = await Promise.all(promises); |
| 332 | for (let n = 0; n < values.length; ++n) { |
| 333 | const tensorToDispose = this.history[keys[n]][indices[n]] as Tensor; |
| 334 | tensorToDispose.dispose(); |
| 335 | this.history[keys[n]][indices[n]] = values[n][0]; |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | export interface CustomCallbackArgs { |