mirror of
https://github.com/huggingface/candle.git
synced 2025-06-16 18:48:51 +00:00
Fix: pth files don't load on Windows (#1661)
* Don't treat zip path as OS path * Add a test case * Add code to generate test pth data
This commit is contained in:
@ -227,13 +227,11 @@ impl Object {
|
|||||||
_ => return Ok(None),
|
_ => return Ok(None),
|
||||||
};
|
};
|
||||||
let (layout, dtype, file_path, storage_size) = rebuild_args(args)?;
|
let (layout, dtype, file_path, storage_size) = rebuild_args(args)?;
|
||||||
let mut path = dir_name.to_path_buf();
|
|
||||||
path.push(file_path);
|
|
||||||
Ok(Some(TensorInfo {
|
Ok(Some(TensorInfo {
|
||||||
name,
|
name,
|
||||||
dtype,
|
dtype,
|
||||||
layout,
|
layout,
|
||||||
path: path.to_string_lossy().into_owned(),
|
path: format!("{}/{}", dir_name.to_string_lossy(), file_path),
|
||||||
storage_size,
|
storage_size,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
8
candle-core/tests/pth.py
Normal file
8
candle-core/tests/pth.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import torch
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
# Write a trivial tensor to a pt file
|
||||||
|
a= torch.tensor([[1,2,3,4], [5,6,7,8]])
|
||||||
|
o = OrderedDict()
|
||||||
|
o["test"] = a
|
||||||
|
torch.save(o, "test.pt")
|
6
candle-core/tests/pth_tests.rs
Normal file
6
candle-core/tests/pth_tests.rs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/// Regression test for pth files not loading on Windows.
|
||||||
|
#[test]
|
||||||
|
fn test_pth() {
|
||||||
|
let tensors = candle_core::pickle::PthTensors::new("tests/test.pt").unwrap();
|
||||||
|
tensors.get("test").unwrap().unwrap();
|
||||||
|
}
|
BIN
candle-core/tests/test.pt
Normal file
BIN
candle-core/tests/test.pt
Normal file
Binary file not shown.
Reference in New Issue
Block a user