(data)
| 481 | // TODO: Maybe track by dtype as well. |
| 482 | // TODO: Maybe distinguish between visible size and storage size. |
| 483 | function getTensorStorages(data) { |
| 484 | if (data === null) { |
| 485 | return new Map(); |
| 486 | } |
| 487 | if (typeof(data) == "boolean") { |
| 488 | return new Map(); |
| 489 | } |
| 490 | if (typeof(data) == "number") { |
| 491 | return new Map(); |
| 492 | } |
| 493 | if (typeof(data) == "string") { |
| 494 | return new Map(); |
| 495 | } |
| 496 | if (typeof(data) != "object") { |
| 497 | throw new Error("Not an object"); |
| 498 | } |
| 499 | if (Array.isArray(data)) { |
| 500 | let result = new Map(); |
| 501 | for (const item of data) { |
| 502 | const tensors = getTensorStorages(item); |
| 503 | for (const [key, storage] of tensors.entries()) { |
| 504 | if (!result.has(key)) { |
| 505 | result.set(key, storage); |
| 506 | } else { |
| 507 | const old_storage = result.get(key); |
| 508 | assertStorageAreEqual(key, old_storage, storage); |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | return result; |
| 513 | } |
| 514 | if (data.__tuple_values__) { |
| 515 | return getTensorStorages(data.__tuple_values__); |
| 516 | } |
| 517 | if (data.__is_dict__) { |
| 518 | return getTensorStorages(data.values); |
| 519 | } |
| 520 | if (data.__module_type__) { |
| 521 | return getTensorStorages(data.state); |
| 522 | } |
| 523 | if (data.__tensor_v2__) { |
| 524 | const [storage, offset, size, stride, grad] = data.__tensor_v2__; |
| 525 | const [dtype, key, device, numel] = storage; |
| 526 | return new Map([[key, storage]]); |
| 527 | } |
| 528 | if (data.__qtensor__) { |
| 529 | const [storage, offset, size, stride, quantizer, grad] = data.__qtensor__; |
| 530 | const [dtype, key, device, numel] = storage; |
| 531 | return new Map([[key, storage]]); |
| 532 | } |
| 533 | throw new Error("Can't handle data type.", data); |
| 534 | } |
| 535 | |
| 536 | function getTensorMemoryByDevice(pickles) { |
| 537 | let all_tensors = []; |
no test coverage detected
searching dependent graphs…