Implementation:Trailofbits Fickling Identify Pytorch File Format
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Security, File_Format, Supply_Chain |
| Last Updated | 2026-02-14 14:00 GMT |
Overview
Concrete tool for classifying PyTorch file formats and detecting polyglot conditions provided by the Fickling library.
Description
identify_pytorch_file_format calls find_file_properties internally, then applies format matching rules to produce an ordered list of detected formats. The first element is the most likely format. Multiple elements indicate a polyglot file. An empty list means the file is not recognized as any PyTorch format.
Usage
Use this to determine what format a PyTorch file is in, and to detect polyglot conditions that may indicate supply chain attacks.
Code Reference
Source Location
- Repository: fickling
- File: fickling/polyglot.py
- Lines: L276-333
Signature
def identify_pytorch_file_format(
file: str,
print_properties: bool = False,
print_results: bool = False
) -> list[str]:
"""Identify PyTorch file format(s) ranked by likelihood.
Args:
file: Path to the file to identify.
print_properties: Print property discovery to stdout.
print_results: Print format identification results.
Returns:
Ordered list of format names. Possible values:
"TorchScript v1.4", "TorchScript v1.3",
"TorchScript v1.0", "TorchScript v1.1",
"PyTorch v1.3", "PyTorch v0.1.1",
"PyTorch v0.1.10", "PyTorch model archive format".
Empty list if unrecognized.
"""
Import
from fickling.polyglot import identify_pytorch_file_format
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| file | str | Yes | Path to the PyTorch file to identify |
| print_properties | bool | No | Print property discovery (default: False) |
| print_results | bool | No | Print format identification results (default: False) |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | list[str] | Ordered list of detected format names; first is most likely |
Usage Examples
Identify File Format
from fickling.polyglot import identify_pytorch_file_format
formats = identify_pytorch_file_format("model.pt", print_results=True)
if len(formats) == 0:
print("Not a recognized PyTorch file")
elif len(formats) == 1:
print(f"Format: {formats[0]}")
else:
print(f"POLYGLOT DETECTED: {formats}")
print(f"Primary: {formats[0]}, Also: {formats[1:]}")
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment