mirror of
https://github.com/huggingface/candle.git
synced 2025-06-17 19:18:50 +00:00
Speedup ShardedSafeTensors to load Tensors with default hints (#1384)
* Speedup ShardedSafeTensors to load Tensors with default hints * Tweaks. --------- Co-authored-by: Laurent <laurent.mazare@gmail.com>
This commit is contained in:
@ -535,12 +535,18 @@ impl Backend for ShardedSafeTensors {
|
|||||||
|
|
||||||
fn get(
|
fn get(
|
||||||
&self,
|
&self,
|
||||||
_target_shape: Shape, // The size is not checked for ShardedTensors
|
target_shape: Shape, // The size is only checked when the world size is 1.
|
||||||
path: &str,
|
path: &str,
|
||||||
h: Self::Hints,
|
h: Self::Hints,
|
||||||
dtype: DType,
|
dtype: DType,
|
||||||
dev: &Device,
|
dev: &Device,
|
||||||
) -> Result<Tensor> {
|
) -> Result<Tensor> {
|
||||||
|
if h.world_size == 1 {
|
||||||
|
// There is no sharding to be applied here so we use the default backend to speed
|
||||||
|
// things up.
|
||||||
|
return SimpleBackend::get(&self.0, target_shape, path, Default::default(), dtype, dev);
|
||||||
|
}
|
||||||
|
|
||||||
let Shard {
|
let Shard {
|
||||||
dim,
|
dim,
|
||||||
rank,
|
rank,
|
||||||
|
Reference in New Issue
Block a user