Metadata-Version: 2.4
Name: pt-safe-loader
Version: 0.1.1
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Rust
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Dist: numpy>=1.24
License-File: LICENSE
Summary: Safe parser-based PyTorch checkpoint converter to safetensors
Home-Page: https://github.com/a-gradient/pt-loader
License-Expression: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/a-gradient/pt-loader
Project-URL: Issues, https://github.com/a-gradient/pt-loader/issues
Project-URL: Repository, https://github.com/a-gradient/pt-loader

# pt-loader

Safe parser-based PyTorch checkpoint converter to safetensors with both Rust and Python APIs.

## Features

- Parses torch zip `.pt` checkpoints with strict safety limits.
- Converts checkpoints to `model.safetensors` + `model.yaml`.
- Inspects checkpoint metadata and tensor summaries.
- Loads tensors directly into Python as NumPy arrays.

## Python Usage

Install from source (local repo):

```bash
uv sync --group dev
uv run pytest -q
```

Example:

```python
import pt_loader

report = pt_loader.inspect("samples/yolo26n.pt")
print(report["tensor_count"])

result = pt_loader.convert("samples/yolo26n.pt", out_dir="out")
print(result["safetensors_path"])

tensors = pt_loader.load_pt("samples/yolo26n.pt")
print(next(iter(tensors.values())).shape)
```

## Rust Usage

```rust
use pt_loader::{convert_pt_to_safetensors, inspect_pt, ConvertOptions};
use std::path::Path;

let report = inspect_pt(Path::new("samples/yolo26n.pt"))?;
let result = convert_pt_to_safetensors(
    Path::new("samples/yolo26n.pt"),
    Path::new("out"),
    ConvertOptions::default(),
)?;
```

## Development

```bash
cargo test
cargo check --features pyo3
uv run pytest -q
```

## Releasing

- Tag a release as `vX.Y.Z`.
- GitHub Actions workflow `.github/workflows/release.yml` will:
  - publish to crates.io using `CRATES_IO_TOKEN`
  - build and publish to PyPI via trusted publishing

