hf-model-viewer / src /types.ts
tfrere's picture
tfrere HF Staff
Deploy hf-model-viewer 2026-05-22T16:59:58Z
fc01079 verified
// Internal IR (Intermediate Representation) for any model graph.
// We deliberately decouple from ONNX so we can later add other backends
// (TensorFlow SavedModel, GGUF metadata, raw config.json heuristics, etc.)
// without touching the rendering layer.
export type TensorShape = (number | string)[];
export interface IRTensorInfo {
name: string;
shape: TensorShape;
dtype: string;
}
export interface IRWeight {
name: string;
shape: number[];
dtype: string;
numParams: number;
}
export interface IRNode {
id: string;
opType: string;
name: string;
inputs: string[];
outputs: string[];
attrs: Record<string, unknown>;
weights: IRWeight[];
}
export type IREdgeKind = "tree" | "forward" | "residual";
export interface IREdge {
id: string;
source: string;
target: string;
tensor: string;
shape?: TensorShape;
dtype?: string;
/**
* Visual classification, used by the renderer to pick a style:
* - `tree` parent→child structural edge (default for legacy paths)
* - `forward` real forward()-pass edge synthesised from a template
* - `residual` residual / skip connection
*/
kind?: IREdgeKind;
}
export interface IRGraphMeta {
modelName: string;
producer: string;
irVersion: number;
opsetVersion: number;
totalParams: number;
nodeCount: number;
inputs: IRTensorInfo[];
outputs: IRTensorInfo[];
/** HF `model_type` from config.json (e.g. "llama", "gpt2", "bert"). Used to
* generate human-friendly Python class names like LlamaDecoderLayer. */
modelType?: string;
/** First entry of `architectures` from config.json (e.g. "LlamaForCausalLM"). */
architecture?: string;
}
export interface IRGraph {
nodes: IRNode[];
edges: IREdge[];
meta: IRGraphMeta;
}
export interface ResolvedModel {
repoId: string;
filePath: string;
url: string;
sizeBytes: number;
hasExternalData: boolean;
}
export interface LoadProgress {
phase: "resolving" | "streaming" | "building" | "laying-out" | "done";
message: string;
/** Bytes received from the network so far. */
loaded?: number;
/** Total file size (for context) — note streaming may finish earlier. */
total?: number;
}