spark.deleteFile
function deleteFile(path: string): Promise<void>Delete a file from torchjs.org.
Removes a file from the server. Like save, this supports both direct deletion (in authenticated contexts) and RPC-proxied deletion (in sandboxed iframes).
Use this to:
- Remove outdated checkpoints or intermediate results
- Clean up unused files to save storage
- Correct mistakes or remove failed experiments
Deletion is permanent. Consider making a backup or using version numbers in filenames before deleting.
Parameters
pathstring- File path in format "username/project/filename" or "username/project/path/to/file"
Returns
Promise<void>– Promise that resolves when file is deletedExamples
// Delete outdated checkpoint
await spark.delete('kasumi/mnist/checkpoint-old.pt');
// Delete a temporary file
await spark.delete('kasumi/project/temp-output.txt');
// Conditional deletion (delete old file before saving new one)
if (await spark.exists('kasumi/model/weights-v1.pt')) {
await spark.delete('kasumi/model/weights-v1.pt');
}
await spark.save('kasumi/model/weights-v2.pt', newWeights);