Skip to content

Reference implementation for the hash calculation #1

@Nerogar

Description

@Nerogar

According to the spec, the hash should be calculated as "A hash of all tensor content (ie excluding the header section), with 0x prefix, all lowercase, and no byte-separator symbols."

I'm assuming this means we need to calculate the hash of the data as it is saved in the safetensors file itself. For validation of an existing file this is fine, but how do we calculate that hash before saving a model?

Do we need to save the model, read it to calculate the hash, then save it again with the hash included? The safetensors library provides a save function to save into a byte array. But I assume this creates a copy of the entire model in RAM, which is not ideal for big models.

An efficient reference implementation would be nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions