tensorrtx icon indicating copy to clipboard operation
tensorrtx copied to clipboard

从wts文件读取权重数据,应该是hex的float值, 为什么存储在 uint32_t中啊

Open HouLingLXH opened this issue 1 year ago • 2 comments

问一下下面这段代码中, 是从wts文件读取权重数据,应该是hex的float值, 为什么存储在 uint32_t中啊?

while (count--) { Weights wt{ DataType::kFLOAT, nullptr, 0 }; uint32_t size;

// Read name and type of blob
std::string name;
input >> name >> std::dec >> size;
wt.type = DataType::kFLOAT;

// Load blob
uint32_t* val = reinterpret_cast<uint32_t*>(malloc(sizeof(val) * size));
for (uint32_t x = 0, y = size; x < y; ++x) {
  input >> std::hex >> val[x];
}
wt.values = val;

wt.count = size;
weightMap[name] = wt;

}

HouLingLXH avatar Dec 13 '23 08:12 HouLingLXH

这里是二进制转换,用uint32_t存储二进制值,这个二进制值实际表示的是float

wang-xinyu avatar Dec 15 '23 02:12 wang-xinyu

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 14 '24 00:02 stale[bot]