diff --git a/CHANGELOG.md b/CHANGELOG.md index 589accf98..86366c21b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,7 +63,7 @@ This documents the main changes to the `candle` crate. [760](https://github.com/huggingface/candle/pull/760). - Add the Segment-Anything Model (SAM) as an example [773](https://github.com/huggingface/candle/pull/773). -- TinyViT backbone for the segemnt anything example +- TinyViT backbone for the segment anything example [787](https://github.com/huggingface/candle/pull/787). - Shape with holes support [770](https://github.com/huggingface/candle/pull/770). diff --git a/README.md b/README.md index 427a2c673..26a81642f 100644 --- a/README.md +++ b/README.md @@ -144,8 +144,10 @@ And then head over to ## Useful External Resources - [`candle-tutorial`](https://github.com/ToluClassics/candle-tutorial): A very detailed tutorial showing how to convert a PyTorch model to Candle. -- [`candle-lora`](https://github.com/EricLBuehler/candle-lora): Efficient and ergonomic LoRA implemenation for Candle. `candle-lora` has - out-of-the-box LoRA support for many models from Candle, which can be found [here](https://github.com/EricLBuehler/candle-lora/tree/master/candle-lora-transformers/examples). +- [`candle-lora`](https://github.com/EricLBuehler/candle-lora): Efficient and + ergonomic LoRA implementation for Candle. `candle-lora` has + out-of-the-box LoRA support for many models from Candle, which can be found + [here](https://github.com/EricLBuehler/candle-lora/tree/master/candle-lora-transformers/examples). - [`optimisers`](https://github.com/KGrewal1/optimisers): A collection of optimisers including SGD with momentum, AdaGrad, AdaDelta, AdaMax, NAdam, RAdam, and RMSprop. - [`candle-vllm`](https://github.com/EricLBuehler/candle-vllm): Efficient platform for inference and diff --git a/candle-book/src/apps/dekstop.md b/candle-book/src/apps/desktop.md similarity index 100% rename from candle-book/src/apps/dekstop.md rename to candle-book/src/apps/desktop.md diff --git a/candle-core/src/indexer.rs b/candle-core/src/indexer.rs index df106b730..e3ed41e52 100644 --- a/candle-core/src/indexer.rs +++ b/candle-core/src/indexer.rs @@ -64,7 +64,7 @@ impl Tensor { #[derive(Debug)] /// Generic structure used to index a slice of the tensor pub enum TensorIndexer { - /// This selects the elemnts for which an index has some specific value. + /// This selects the elements for which an index has some specific value. Select(usize), /// This is a regular slice, purely indexing a chunk of the tensor Narrow(Bound, Bound), diff --git a/candle-core/src/quantized/avx.rs b/candle-core/src/quantized/avx.rs index 5c3ac822e..664f7653e 100644 --- a/candle-core/src/quantized/avx.rs +++ b/candle-core/src/quantized/avx.rs @@ -353,7 +353,7 @@ pub(crate) fn vec_dot_q3k_q8k(n: usize, xs: &[BlockQ3K], ys: &[BlockQ8K]) -> Res q3 = q3.add(32); // Prepare low and high bits - // We hardcode the shifts here to avoid loading them into a seperate register + // We hardcode the shifts here to avoid loading them into a separate register let q3l_0 = _mm256_and_si256(q3bits, m3); let q3h_0 = if j == 0 { _mm256_srli_epi16(_mm256_andnot_si256(hbits, _mm256_slli_epi16(mone, 0)), 0) @@ -586,7 +586,7 @@ pub(crate) fn vec_dot_q5k_q8k(n: usize, xs: &[BlockQ5K], ys: &[BlockQ8K]) -> Res let q5bits = _mm256_loadu_si256(q5 as *const __m256i); q5 = q5.add(32); - //Similar to q3k we hardcode the shifts here to avoid loading them into a seperate register + //Similar to q3k we hardcode the shifts here to avoid loading them into a separate register let q5l_0 = _mm256_and_si256(q5bits, m4); let q5l_0_shift_input = _mm256_and_si256(hbits, hmask); let q5l_0_right_shift = match j { diff --git a/candle-core/src/quantized/gguf_file.rs b/candle-core/src/quantized/gguf_file.rs index 620bc0375..1e9dc5174 100644 --- a/candle-core/src/quantized/gguf_file.rs +++ b/candle-core/src/quantized/gguf_file.rs @@ -463,7 +463,7 @@ impl Content { ) -> Result { let tensor_info = match self.tensor_infos.get(name) { Some(tensor_info) => tensor_info, - None => crate::bail!("cannot find tensor-infor for {name}"), + None => crate::bail!("cannot find tensor info for {name}"), }; tensor_info.read(reader, self.tensor_data_offset) } diff --git a/candle-core/src/tensor.rs b/candle-core/src/tensor.rs index 8950f2c5f..e1cae41c6 100644 --- a/candle-core/src/tensor.rs +++ b/candle-core/src/tensor.rs @@ -1,4 +1,4 @@ -//! Tensors are N-dimenional matrixes of elements using a single data type. +//! Tensors are N-dimensional matrixes of elements using a single data type. #![allow(clippy::redundant_closure_call)] use crate::backend::{BackendDevice, BackendStorage}; use crate::op::{ @@ -669,7 +669,7 @@ impl Tensor { } /// Split a tensor into the specified number of chunks, this may return less chunks than - /// specificed. + /// specified. pub fn chunk(&self, chunks: usize, dim: D) -> Result> { let dim = dim.to_index(self.shape(), "chunk")?; let size = self.dim(dim)?; diff --git a/candle-examples/examples/reinforcement-learning/atari_wrappers.py b/candle-examples/examples/reinforcement-learning/atari_wrappers.py index b5c4665dc..b76fb85d5 100644 --- a/candle-examples/examples/reinforcement-learning/atari_wrappers.py +++ b/candle-examples/examples/reinforcement-learning/atari_wrappers.py @@ -78,7 +78,7 @@ def step(self, action): # then update lives to handle bonus lives lives = self.env.unwrapped.ale.lives() if lives < self.lives and lives > 0: - # for Qbert somtimes we stay in lives == 0 condtion for a few frames + # for Qbert sometimes we stay in lives == 0 condition for a few frames # so its important to keep lives > 0, so that we only reset once # the environment advertises done. done = True diff --git a/candle-nn/src/var_builder.rs b/candle-nn/src/var_builder.rs index 9d245f12a..83c86a6f3 100644 --- a/candle-nn/src/var_builder.rs +++ b/candle-nn/src/var_builder.rs @@ -40,7 +40,7 @@ struct TensorData { /// A trait that defines how tensor data is retrieved. /// /// Typically this would use disk storage in some specific format, or random initialization. -/// Note that there is a speciliazed version of this trait (`SimpleBackend`) that can be used most +/// Note that there is a specialized version of this trait (`SimpleBackend`) that can be used most /// of the time. The main restriction is that it doesn't allow for specific args (besides /// initialization hints). pub trait Backend: Send + Sync { diff --git a/candle-pyo3/py_src/candle/__init__.py b/candle-pyo3/py_src/candle/__init__.py index 38718a46c..e0e188cb7 100644 --- a/candle-pyo3/py_src/candle/__init__.py +++ b/candle-pyo3/py_src/candle/__init__.py @@ -4,7 +4,8 @@ from .candle import * except ImportError as e: # If we are in development mode, or we did not bundle the DLLs, we try to locate them here - # PyO3 wont give us any infomration about what DLLs are missing, so we can only try to load the DLLs and re-import the module + # PyO3 wont give us any information about what DLLs are missing, so we can only try to load + # the DLLs and re-import the module logging.warning("DLLs were not bundled with this package. Trying to locate them...") import os import platform diff --git a/candle-pyo3/py_src/candle/nn/container.py b/candle-pyo3/py_src/candle/nn/container.py index 15ed8dd23..6ece31b6d 100644 --- a/candle-pyo3/py_src/candle/nn/container.py +++ b/candle-pyo3/py_src/candle/nn/container.py @@ -363,7 +363,7 @@ def extend(self, modules: Iterable[Module]) -> "ModuleList": self.add_module(str(offset + i), module) return self - # remove forward alltogether to fallback on Module's _forward_unimplemented + # remove forward altogether to fallback on Module's _forward_unimplemented class ModuleDict(Module): @@ -480,4 +480,4 @@ def update(self, modules: Mapping[str, Module]) -> None: # that's too cumbersome to type correctly with overloads, so we add an ignore here self[m[0]] = m[1] # type: ignore[assignment] - # remove forward alltogether to fallback on Module's _forward_unimplemented + # remove forward altogether to fallback on Module's _forward_unimplemented diff --git a/candle-pyo3/src/lib.rs b/candle-pyo3/src/lib.rs index ade000129..90826b98b 100644 --- a/candle-pyo3/src/lib.rs +++ b/candle-pyo3/src/lib.rs @@ -212,7 +212,7 @@ trait MapDType { enum Indexer { Index(usize), Slice(usize, usize), - Elipsis, + Ellipsis, Expand, IndexSelect(Tensor), } @@ -568,7 +568,7 @@ impl PyTensor { "Ellipsis ('...') can only be used at the start of an indexing operation", )); } - Ok((Indexer::Elipsis, dims.len() - (index_argument_count - 1))) + Ok((Indexer::Ellipsis, dims.len() - (index_argument_count - 1))) } else if py_indexer.is_none() { // Handle None e.g. tensor[None, 0] Ok((Indexer::Expand, current_dim)) @@ -616,8 +616,9 @@ impl PyTensor { current_dim += 1; out } - Indexer::Elipsis => { - // Elipsis is a special case, it means that all remaining dimensions should be selected => advance the current_dim to the last dimension we have indexers for + Indexer::Ellipsis => { + // Ellipsis is a special case, it means that all remaining dimensions should be + // selected => advance the current_dim to the last dimension we have indexers for current_dim += dims.len() - (indexers.len() - 1); x } @@ -960,11 +961,11 @@ impl PyTensor { extraction_result: PyResult, err_msg: &'static str, ) -> PyResult<()> { - if let Ok(sucessfull_extraction) = extraction_result { + if let Ok(successful_extraction) = extraction_result { if opt.is_some() { return Err(PyValueError::new_err(err_msg)); } - *opt = Some(sucessfull_extraction); + *opt = Some(successful_extraction); } Ok(()) } @@ -1045,9 +1046,7 @@ impl PyTensor { .map_err(wrap_err)?, (Some(device), None) => self.0.to_device(&device.as_device()?).map_err(wrap_err)?, (None, Some(dtype)) => self.0.to_dtype(dtype.0).map_err(wrap_err)?, - (None, None) => { - return Err(PyTypeError::new_err("No valide dtype or device specified")) - } + (None, None) => return Err(PyTypeError::new_err("No valid dtype or device specified")), }; Ok(PyTensor(result)) diff --git a/candle-pyo3/stub.py b/candle-pyo3/stub.py index 336f674ba..c459ebb39 100644 --- a/candle-pyo3/stub.py +++ b/candle-pyo3/stub.py @@ -156,7 +156,7 @@ def process_additional_function(fn): string += function(obj, indent) elif inspect.isgetsetdescriptor(obj): - # TODO it would be interesing to add the setter maybe ? + # TODO it would be interesting to add the setter maybe ? string += f"{indent}@property\n" string += function(obj, indent, text_signature="(self)") diff --git a/candle-pyo3/tests/bindings/test_module.py b/candle-pyo3/tests/bindings/test_module.py index 819dae5be..8d7a670de 100644 --- a/candle-pyo3/tests/bindings/test_module.py +++ b/candle-pyo3/tests/bindings/test_module.py @@ -74,7 +74,7 @@ def __init__(self): a.load_state_dict(statedict) -def test_module_throws_on_shape_missmatch(): +def test_module_throws_on_shape_mismatch(): class A(Module): def __init__(self): super().__init__() @@ -121,7 +121,7 @@ def __init__(self): assert a.t.ggml_dtype == "Q4_0" -def test_module_dequantizes_tensors_automaticaly(): +def test_module_dequantizes_tensors_automatically(): class A(Module): def __init__(self): super().__init__() diff --git a/candle-pyo3/tests/native/test_tensor.py b/candle-pyo3/tests/native/test_tensor.py index ef44fc4c9..04eaca0da 100644 --- a/candle-pyo3/tests/native/test_tensor.py +++ b/candle-pyo3/tests/native/test_tensor.py @@ -84,7 +84,7 @@ def assert_bool(t: Tensor, expected: bool): assert bool(t.values()) == expected -def test_tensor_supports_equality_opperations_with_scalars(): +def test_tensor_supports_equality_operations_with_scalars(): t = Tensor(42.0) assert_bool(t == 42.0, True) @@ -106,7 +106,7 @@ def test_tensor_supports_equality_opperations_with_scalars(): assert_bool(t <= 42.0, True) -def test_tensor_supports_equality_opperations_with_tensors(): +def test_tensor_supports_equality_operations_with_tensors(): t = Tensor(42.0) same = Tensor(42.0) other = Tensor(43.0) @@ -130,7 +130,7 @@ def test_tensor_supports_equality_opperations_with_tensors(): assert_bool(t <= other, True) -def test_tensor_equality_opperations_can_broadcast(): +def test_tensor_equality_operations_can_broadcast(): # Create a decoder attention mask as a test case # e.g. # [[1,0,0] diff --git a/candle-transformers/src/models/segment_anything/mask_decoder.rs b/candle-transformers/src/models/segment_anything/mask_decoder.rs index 2a91cd447..1703c8097 100644 --- a/candle-transformers/src/models/segment_anything/mask_decoder.rs +++ b/candle-transformers/src/models/segment_anything/mask_decoder.rs @@ -182,7 +182,7 @@ impl MaskDecoder { sparse_prompt_embeddings: &Tensor, dense_prompt_embeddings: &Tensor, ) -> Result<(Tensor, Tensor)> { - // Concatenate ouput tokens. + // Concatenate output tokens. let output_tokens = Tensor::cat( &[self.iou_token.embeddings(), self.mask_tokens.embeddings()], 0, diff --git a/candle-transformers/src/models/segment_anything/prompt_encoder.rs b/candle-transformers/src/models/segment_anything/prompt_encoder.rs index 9d0074b1e..16e8a4e88 100644 --- a/candle-transformers/src/models/segment_anything/prompt_encoder.rs +++ b/candle-transformers/src/models/segment_anything/prompt_encoder.rs @@ -2,11 +2,11 @@ use candle::{DType, IndexOp, Result, Tensor, D}; use candle_nn::VarBuilder; #[derive(Debug)] -struct PostionEmbeddingRandom { +struct PositionEmbeddingRandom { positional_encoding_gaussian_matrix: Tensor, } -impl PostionEmbeddingRandom { +impl PositionEmbeddingRandom { fn new(num_pos_feats: usize, vb: VarBuilder) -> Result { let positional_encoding_gaussian_matrix = vb.get((2, num_pos_feats), "positional_encoding_gaussian_matrix")?; @@ -52,7 +52,7 @@ impl PostionEmbeddingRandom { #[derive(Debug)] pub struct PromptEncoder { - pe_layer: PostionEmbeddingRandom, + pe_layer: PositionEmbeddingRandom, point_embeddings: Vec, not_a_point_embed: candle_nn::Embedding, mask_downscaling_conv1: candle_nn::Conv2d, @@ -76,7 +76,7 @@ impl PromptEncoder { vb: VarBuilder, ) -> Result { let num_points_embeddings = 4; - let pe_layer = PostionEmbeddingRandom::new(embed_dim / 2, vb.pp("pe_layer"))?; + let pe_layer = PositionEmbeddingRandom::new(embed_dim / 2, vb.pp("pe_layer"))?; let not_a_point_embed = candle_nn::embedding(1, embed_dim, vb.pp("not_a_point_embed"))?; let no_mask_embed = candle_nn::embedding(1, embed_dim, vb.pp("no_mask_embed"))?; let cfg = candle_nn::Conv2dConfig { diff --git a/candle-transformers/src/models/stable_diffusion/euler_ancestral_discrete.rs b/candle-transformers/src/models/stable_diffusion/euler_ancestral_discrete.rs index 85e86e6e9..9576c2de4 100644 --- a/candle-transformers/src/models/stable_diffusion/euler_ancestral_discrete.rs +++ b/candle-transformers/src/models/stable_diffusion/euler_ancestral_discrete.rs @@ -1,6 +1,6 @@ //! Ancestral sampling with Euler method steps. //! -//! Reference implemenation in Rust: +//! Reference implementation in Rust: //! //! https://github.com/pykeio/diffusers/blob/250b9ad1898af41e76a74c0d8d4292652823338a/src/schedulers/euler_ancestral_discrete.rs //! @@ -135,7 +135,7 @@ impl EulerAncestralDiscreteScheduler { ); sigmas_int.push(0.0); - // standard deviation of the inital noise distribution + // standard deviation of the initial noise distribution // f64 does not implement Ord such that there is no `max`, so we need to use this workaround let init_noise_sigma = *sigmas_int .iter() diff --git a/candle-wasm-examples/llama2-c/src/app.rs b/candle-wasm-examples/llama2-c/src/app.rs index ea04a8106..f254a5ae8 100644 --- a/candle-wasm-examples/llama2-c/src/app.rs +++ b/candle-wasm-examples/llama2-c/src/app.rs @@ -108,7 +108,7 @@ impl Component for App { fn update(&mut self, ctx: &Context, msg: Self::Message) -> bool { match msg { Msg::SetModel(md) => { - self.status = "weights loaded succesfully!".to_string(); + self.status = "weights loaded successfully!".to_string(); self.loaded = true; console_log!("loaded weights"); self.worker.send(WorkerInput::ModelData(md)); diff --git a/candle-wasm-examples/llama2-c/src/worker.rs b/candle-wasm-examples/llama2-c/src/worker.rs index 79dd2f324..e38561b9c 100644 --- a/candle-wasm-examples/llama2-c/src/worker.rs +++ b/candle-wasm-examples/llama2-c/src/worker.rs @@ -24,7 +24,7 @@ macro_rules! console_log { } // Communication to the worker happens through bincode, the model weights and configs are fetched -// on the main thread and transfered via the following structure. +// on the main thread and transferred via the following structure. #[derive(Serialize, Deserialize)] pub struct ModelData { pub tokenizer: Vec, diff --git a/candle-wasm-examples/whisper/src/app.rs b/candle-wasm-examples/whisper/src/app.rs index 1bc913d54..1cb311931 100644 --- a/candle-wasm-examples/whisper/src/app.rs +++ b/candle-wasm-examples/whisper/src/app.rs @@ -145,7 +145,7 @@ impl Component for App { fn update(&mut self, ctx: &Context, msg: Self::Message) -> bool { match msg { Msg::SetDecoder(md) => { - self.status = "weights loaded succesfully!".to_string(); + self.status = "weights loaded successfully!".to_string(); self.loaded = true; console_log!("loaded weights"); self.worker.send(WorkerInput::ModelData(md)); diff --git a/candle-wasm-examples/whisper/src/worker.rs b/candle-wasm-examples/whisper/src/worker.rs index db5e8bb14..fd91fa8c1 100644 --- a/candle-wasm-examples/whisper/src/worker.rs +++ b/candle-wasm-examples/whisper/src/worker.rs @@ -414,7 +414,7 @@ pub enum Task { } // Communication to the worker happens through bincode, the model weights and configs are fetched -// on the main thread and transfered via the following structure. +// on the main thread and transferred via the following structure. #[derive(Serialize, Deserialize)] pub struct ModelData { pub weights: Vec, diff --git a/candle-wasm-examples/yolo/src/app.rs b/candle-wasm-examples/yolo/src/app.rs index 0df61f0f8..3a88a5f1d 100644 --- a/candle-wasm-examples/yolo/src/app.rs +++ b/candle-wasm-examples/yolo/src/app.rs @@ -146,7 +146,7 @@ impl Component for App { fn update(&mut self, ctx: &Context, msg: Self::Message) -> bool { match msg { Msg::SetModel(md) => { - self.status = "weights loaded succesfully!".to_string(); + self.status = "weights loaded successfully!".to_string(); self.loaded = true; console_log!("loaded weights"); self.worker.send(WorkerInput::ModelData(md)); diff --git a/candle-wasm-examples/yolo/src/worker.rs b/candle-wasm-examples/yolo/src/worker.rs index 5733a3fde..1ecef3417 100644 --- a/candle-wasm-examples/yolo/src/worker.rs +++ b/candle-wasm-examples/yolo/src/worker.rs @@ -21,7 +21,7 @@ macro_rules! console_log { } // Communication to the worker happens through bincode, the model weights and configs are fetched -// on the main thread and transfered via the following structure. +// on the main thread and transferred via the following structure. #[derive(Serialize, Deserialize)] pub struct ModelData { pub weights: Vec,