| 439 | for (auto & item : items) { |
| 440 | stack_.back().items.push_back(std::move(item)); |
| 441 | } |
| 442 | } |
| 443 | std::vector<PickleValue> finish() { |
| 444 | const PickleValue result = pop(); |
| 445 | if (result.kind == PickleValue::Kind::Tensor) { |
| 446 | return {str_value("tensor"), result}; |
| 447 | } |
| 448 | if (result.kind != PickleValue::Kind::Dict) { |
| 449 | throw std::runtime_error("torch .bin pickle did not produce a state dict"); |
| 450 | } |
| 451 | // A training checkpoint saved as {"state_dict": ..., "metadata": ...} (Semantic-DACVAE's |
| 452 | // weights.pth) keeps its weights in the inner dict; the rest is not tensor data. |
| 453 | for (size_t i = 0; i + 1 < result.items.size(); i += 2) { |
| 454 | if (result.items[i].kind == PickleValue::Kind::Str && result.items[i].text == "state_dict" && |
| 455 | result.items[i + 1].kind == PickleValue::Kind::Dict) { |
| 456 | return result.items[i + 1].items; |
no test coverage detected