gpuLoadTensor (Function)

Signature: gpuLoadTensor(path: string, name: string) -> Result<GpuBuffer<t0>, Error>

Description: Reads one named tensor out of a safetensors file into the requested float buffer type: F64 requires float, F32 and BF16 require float32, and F16 requires float16. An unknown name, mismatched request, unsupported dtype or truncated file returns Error.

Parameters

  • path (string): The safetensors file
  • name (string): The tensor's name in the header

Returns: Result<GpuBuffer<t0>, Error>

Example

let loaded: Result<GpuBuffer<float32>, Error> = gpuLoadTensor("model.safetensors", "wte.weight")
match loaded {
    Success { value } => print("${gpuLength(value)} values")
    Error { message } => print(message)
}
let loaded: Result<GpuBuffer<float32>, Error> = gpuLoadTensor ("model.safetensors", "wte.weight")
match loaded
    Success value => print "${gpuLength(value)} values"
    Error message => print message