Skip to content

Commit be4f920

Browse files
authored
clippy fixes (#3053)
1 parent 1829812 commit be4f920

File tree

15 files changed

+47
-45
lines changed

15 files changed

+47
-45
lines changed

candle-core/src/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ impl Layout {
187187
})
188188
}
189189

190-
pub(crate) fn strided_index(&self) -> crate::StridedIndex {
190+
pub(crate) fn strided_index(&self) -> crate::StridedIndex<'_> {
191191
crate::StridedIndex::from_layout(self)
192192
}
193193

194-
pub(crate) fn strided_blocks(&self) -> crate::StridedBlocks {
194+
pub(crate) fn strided_blocks(&self) -> crate::StridedBlocks<'_> {
195195
let mut block_len = 1;
196196
let mut contiguous_dims = 0; // These are counted from the right.
197197
for (&stride, &dim) in self.stride().iter().zip(self.dims().iter()).rev() {

candle-core/src/quantized/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl QStorage {
115115
}
116116
}
117117

118-
fn data(&self) -> Result<Cow<[u8]>> {
118+
fn data(&self) -> Result<Cow<'_, [u8]>> {
119119
match self {
120120
QStorage::Cpu(storage) => {
121121
let data_ptr = storage.as_ptr();

candle-core/src/safetensors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl st::View for Tensor {
5757
self.shape().dims()
5858
}
5959

60-
fn data(&self) -> Cow<[u8]> {
60+
fn data(&self) -> Cow<'_, [u8]> {
6161
// This copies data from GPU to CPU.
6262
// TODO: Avoid the unwrap here.
6363
Cow::Owned(convert_back(self).unwrap())
@@ -78,7 +78,7 @@ impl st::View for &Tensor {
7878
self.dims()
7979
}
8080

81-
fn data(&self) -> Cow<[u8]> {
81+
fn data(&self) -> Cow<'_, [u8]> {
8282
// This copies data from GPU to CPU.
8383
// TODO: Avoid the unwrap here.
8484
Cow::Owned(convert_back(self).unwrap())

candle-core/src/tensor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,15 +1742,15 @@ impl Tensor {
17421742

17431743
/// Returns an iterator over position of the elements in the storage when ranging over the
17441744
/// index tuples in lexicographic order.
1745-
pub fn strided_index(&self) -> crate::StridedIndex {
1745+
pub fn strided_index(&self) -> crate::StridedIndex<'_> {
17461746
self.layout.strided_index()
17471747
}
17481748

17491749
/// Similar to `strided_index` but returns the position of the start of each contiguous block
17501750
/// as well as the length of the contiguous blocks. For a contiguous tensor, the index iterator
17511751
/// will only return the start offset and the size would be the number of elements in the
17521752
/// tensor.
1753-
pub fn strided_blocks(&self) -> crate::StridedBlocks {
1753+
pub fn strided_blocks(&self) -> crate::StridedBlocks<'_> {
17541754
self.layout.strided_blocks()
17551755
}
17561756

candle-examples/examples/chinese_clip/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn main() -> anyhow::Result<()> {
7777
Ok(())
7878
}
7979

80-
pub fn load_weights(model: Option<String>, device: &Device) -> anyhow::Result<nn::VarBuilder> {
80+
pub fn load_weights(model: Option<String>, device: &Device) -> anyhow::Result<nn::VarBuilder<'_>> {
8181
let model_file = match model {
8282
None => {
8383
let api = hf_hub::api::sync::Api::new()?;

candle-examples/examples/clip/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ pub fn main() -> anyhow::Result<()> {
8888
],
8989
};
9090
let images = load_images(&vec_imgs, config.image_size)?.to_device(&device)?;
91-
let vb =
92-
unsafe { VarBuilder::from_mmaped_safetensors(&[model_file.clone()], DType::F32, &device)? };
91+
let vb = unsafe {
92+
VarBuilder::from_mmaped_safetensors(std::slice::from_ref(&model_file), DType::F32, &device)?
93+
};
9394
let model = clip::ClipModel::new(vb, &config)?;
9495
let (input_ids, vec_seq) = tokenize_sequences(args.sequences, &tokenizer, &device)?;
9596
let (_logits_per_text, logits_per_image) = model.forward(&images, &input_ids)?;

candle-examples/examples/distilbert/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl Args {
134134
Ok((config, tokenizer, weights))
135135
}
136136

137-
fn load_variables(&self, weights_path: &PathBuf, device: &Device) -> Result<VarBuilder> {
137+
fn load_variables(&self, weights_path: &PathBuf, device: &Device) -> Result<VarBuilder<'_>> {
138138
if self.use_pth {
139139
Ok(VarBuilder::from_pth(weights_path, DTYPE, device)?)
140140
} else {

candle-examples/examples/mobileclip/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ pub fn main() -> anyhow::Result<()> {
9999
let vb = if args.use_pth {
100100
VarBuilder::from_pth(&model_file, DType::F32, &device)?
101101
} else {
102-
unsafe { VarBuilder::from_mmaped_safetensors(&[model_file.clone()], DType::F32, &device)? }
102+
unsafe {
103+
VarBuilder::from_mmaped_safetensors(
104+
std::slice::from_ref(&model_file),
105+
DType::F32,
106+
&device,
107+
)?
108+
}
103109
};
104110

105111
let model = mobileclip::MobileClipModel::new(vb, config)?;

candle-examples/examples/segformer/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ enum Commands {
5656
Classify(ClassificationArgs),
5757
}
5858

59-
fn get_vb_and_config(model_name: String, device: &Device) -> anyhow::Result<(VarBuilder, Config)> {
59+
fn get_vb_and_config(
60+
model_name: String,
61+
device: &Device,
62+
) -> anyhow::Result<(VarBuilder<'_>, Config)> {
6063
println!("loading model {model_name} via huggingface hub");
6164
let api = hf_hub::api::sync::Api::new()?;
6265
let api = api.model(model_name.clone());

candle-examples/examples/siglip/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ pub fn main() -> anyhow::Result<()> {
139139
args.image_size.unwrap_or(config.vision_config.image_size),
140140
)?
141141
.to_device(&device)?;
142-
let vb =
143-
unsafe { VarBuilder::from_mmaped_safetensors(&[model_file.clone()], DType::F32, &device)? };
142+
let vb = unsafe {
143+
VarBuilder::from_mmaped_safetensors(std::slice::from_ref(&model_file), DType::F32, &device)?
144+
};
144145
let model = siglip::Model::new(&config, vb)?;
145146
let (input_ids, vec_seq) = tokenize_sequences(&config, args.sequences, &tokenizer, &device)?;
146147
let (_logits_per_text, logits_per_image) = model.forward(&images, &input_ids)?;

0 commit comments

Comments
 (0)