Sign In

stInfo: A Simple Tool for Extracting JSON Metadata from Safetensors Files

2

stInfo: A Simple Tool for Extracting JSON Metadata from Safetensors Files

I made a little too that I've decided to release for everyone. stinfois a command-line utility designed for people working with .safetensors files. Available now on GitHub, stinfo makes it easy to have a peek at the metadata embedded in .safetensors files.

Features

  • Verbose Mode (-v): Prints the size of the JSON header.

  • Pretty-Print (-p): Formats the JSON output with proper indentation.

  • Metadata Extraction (-m): Extracts and prints only the __metadata__ object.

How It Works

The .safetensors file format begins with an 8-byte length prefix for the JSON metadata, followed by the metadata itself. stinfo reads this prefix to determine the length, then extracts and optionally formats the JSON data for easy viewing.

Usage

stinfo [options] <filename>

Options:

  • -v: Verbose output, prints the JSON header size.

  • -p: Pretty-print the JSON output with indentation.

  • -m: Print only the __metadata__ object.

  • --?: Show help message and exit.

Example Commands

  • Print the JSON metadata with verbose output:

    stinfo -v example.safetensors

  • Pretty-print the JSON metadata:

    stinfo -p example.safetensors

  • Print only the __metadata__ object:

    stinfo -m example.safetensors

Building the Program

To compile stinfo, you can use GCC:

gcc stinfo.c -o stinfo

For Visual Studio users, make sure to set the build configuration to Release:

  1. Open a new project as a Console App in Visual Studio. Call it stinfo.

  2. Open the code on Github. Copy and Paste the code over the "hello world" code in Visual Studio.

  3. Go to Build > Configuration Manager.

  4. Set Active Solution Configuration to Release.

  5. Close the Configuration Manager.

Get the Code

You can get it on Github right here .

Have fun!

2

Comments