From b57e0bf72f5fcb57e9f86815eaa33aa844e98213 Mon Sep 17 00:00:00 2001 From: Maarten de Vries Date: Thu, 10 Oct 2024 18:50:48 +0200 Subject: [PATCH 1/4] Fix glog for pytorch 2.3.x branch. --- torch-sys/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torch-sys/build.rs b/torch-sys/build.rs index 637bb50e..82fc6240 100644 --- a/torch-sys/build.rs +++ b/torch-sys/build.rs @@ -385,6 +385,7 @@ impl SystemInfo { .flag(&format!("-Wl,-rpath={}", self.libtorch_lib_dir.display())) .flag("-std=c++17") .flag(&format!("-D_GLIBCXX_USE_CXX11_ABI={}", self.cxx11_abi)) + .flag("-DGLOG_USE_GLOG_EXPORT") .files(&c_files) .compile("tch"); } @@ -398,6 +399,7 @@ impl SystemInfo { .warnings(false) .includes(&self.libtorch_include_dirs) .flag("/std:c++17") + .flag("/p:DefineConstants=GLOG_USE_GLOG_EXPORT") .files(&c_files) .compile("tch"); } From a9b1e017b5bc0c4e245792149b39034f18f9ff4b Mon Sep 17 00:00:00 2001 From: Maarten de Vries Date: Thu, 10 Oct 2024 19:16:21 +0200 Subject: [PATCH 2/4] Fix clippy warnings. --- src/nn/init.rs | 4 ++-- torch-sys/build.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nn/init.rs b/src/nn/init.rs index d3bb0b34..44bb10c5 100644 --- a/src/nn/init.rs +++ b/src/nn/init.rs @@ -107,7 +107,7 @@ pub fn f_init(i: Init, dims: &[i64], device: Device) -> Result // Optimize the case for which a single C++ code can be done. if cst == 0. { Tensor::f_zeros(dims, (Kind::Float, device)) - } else if (cst - 1.).abs() <= std::f64::EPSILON { + } else if (cst - 1.).abs() <= f64::EPSILON { Tensor::f_ones(dims, (Kind::Float, device)) } else { Tensor::f_ones(dims, (Kind::Float, device)).map(|t| t * cst) @@ -117,7 +117,7 @@ pub fn f_init(i: Init, dims: &[i64], device: Device) -> Result Tensor::f_zeros(dims, (Kind::Float, device))?.f_uniform_(lo, up) } Init::Randn { mean, stdev } => { - if mean == 0. && (stdev - 1.).abs() <= std::f64::EPSILON { + if mean == 0. && (stdev - 1.).abs() <= f64::EPSILON { Tensor::f_randn(dims, (Kind::Float, device)) } else { Tensor::f_randn(dims, (Kind::Float, device)).map(|t| t * stdev + mean) diff --git a/torch-sys/build.rs b/torch-sys/build.rs index 82fc6240..b75a8285 100644 --- a/torch-sys/build.rs +++ b/torch-sys/build.rs @@ -382,9 +382,9 @@ impl SystemInfo { .pic(true) .warnings(false) .includes(&self.libtorch_include_dirs) - .flag(&format!("-Wl,-rpath={}", self.libtorch_lib_dir.display())) + .flag(format!("-Wl,-rpath={}", self.libtorch_lib_dir.display())) .flag("-std=c++17") - .flag(&format!("-D_GLIBCXX_USE_CXX11_ABI={}", self.cxx11_abi)) + .flag(format!("-D_GLIBCXX_USE_CXX11_ABI={}", self.cxx11_abi)) .flag("-DGLOG_USE_GLOG_EXPORT") .files(&c_files) .compile("tch"); From fa8531bab17db4613f472cbd8ce3fa7547c3afc9 Mon Sep 17 00:00:00 2001 From: laurent Date: Tue, 15 Oct 2024 10:42:00 +0200 Subject: [PATCH 3/4] Bump the minor crate version. --- Cargo.toml | 4 ++-- examples/python-extension/Cargo.toml | 6 +++--- pyo3-tch/Cargo.toml | 8 ++++---- torch-sys/Cargo.toml | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c1513dba..2e602e27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tch" -version = "0.16.0" +version = "0.16.1" authors = ["Laurent Mazare "] edition = "2021" build = "build.rs" @@ -22,7 +22,7 @@ libc = "0.2.0" ndarray = "0.15" rand = "0.8" thiserror = "1" -torch-sys = { version = "0.16.0", path = "torch-sys" } +torch-sys = { version = "0.16.1", path = "torch-sys" } zip = "0.6" half = "2" safetensors = "0.3.0" diff --git a/examples/python-extension/Cargo.toml b/examples/python-extension/Cargo.toml index a312e10c..36ff4138 100644 --- a/examples/python-extension/Cargo.toml +++ b/examples/python-extension/Cargo.toml @@ -18,6 +18,6 @@ crate-type = ["cdylib"] [dependencies] pyo3 = { version = "0.21", features = ["extension-module"] } -pyo3-tch = { path = "../../pyo3-tch", version = "0.16.0" } -tch = { path = "../..", features = ["python-extension"], version = "0.16.0" } -torch-sys = { path = "../../torch-sys", features = ["python-extension"], version = "0.16.0" } \ No newline at end of file +pyo3-tch = { path = "../../pyo3-tch", version = "0.16.1" } +tch = { path = "../..", features = ["python-extension"], version = "0.16.1" } +torch-sys = { path = "../../torch-sys", features = ["python-extension"], version = "0.16.1" } diff --git a/pyo3-tch/Cargo.toml b/pyo3-tch/Cargo.toml index d833aff6..7608ec90 100644 --- a/pyo3-tch/Cargo.toml +++ b/pyo3-tch/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-tch" -version = "0.16.0" +version = "0.16.1" authors = ["Laurent Mazare "] edition = "2021" build = "build.rs" @@ -12,6 +12,6 @@ categories = ["science"] license = "MIT/Apache-2.0" [dependencies] -tch = { path = "..", features = ["python-extension"], version = "0.16.0" } -torch-sys = { path = "../torch-sys", features = ["python-extension"], version = "0.16.0" } -pyo3 = { version = "0.21", features = ["extension-module"] } \ No newline at end of file +tch = { path = "..", features = ["python-extension"], version = "0.16.1" } +torch-sys = { path = "../torch-sys", features = ["python-extension"], version = "0.16.1" } +pyo3 = { version = "0.21", features = ["extension-module"] } diff --git a/torch-sys/Cargo.toml b/torch-sys/Cargo.toml index b23bf0e9..444f6d15 100644 --- a/torch-sys/Cargo.toml +++ b/torch-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "torch-sys" -version = "0.16.0" +version = "0.16.1" authors = ["Laurent Mazare "] edition = "2021" build = "build.rs" From a9d496e468887af6625d462cbf057ef41d24892a Mon Sep 17 00:00:00 2001 From: laurent Date: Tue, 15 Oct 2024 10:44:40 +0200 Subject: [PATCH 4/4] Clippy fixes. --- examples/min-gpt/main.rs | 2 +- examples/yolo/darknet.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/min-gpt/main.rs b/examples/min-gpt/main.rs index 43546b19..66ddd985 100644 --- a/examples/min-gpt/main.rs +++ b/examples/min-gpt/main.rs @@ -80,7 +80,7 @@ fn causal_self_attention(p: &nn::Path, cfg: Config) -> impl ModuleT { let q = xs.apply(&query).view(sizes).transpose(1, 2); let v = xs.apply(&value).view(sizes).transpose(1, 2); let att = q.matmul(&k.transpose(-2, -1)) * (1.0 / f64::sqrt(sizes[3] as f64)); - let att = att.masked_fill(&mask.i((.., .., ..sz_t, ..sz_t)).eq(0.), std::f64::NEG_INFINITY); + let att = att.masked_fill(&mask.i((.., .., ..sz_t, ..sz_t)).eq(0.), f64::NEG_INFINITY); let att = att.softmax(-1, Kind::Float).dropout(cfg.attn_pdrop, train); let ys = att.matmul(&v).transpose(1, 2).contiguous().view([sz_b, sz_t, sz_c]); ys.apply(&proj).dropout(cfg.resid_pdrop, train) diff --git a/examples/yolo/darknet.rs b/examples/yolo/darknet.rs index 0f744057..9ce3b046 100644 --- a/examples/yolo/darknet.rs +++ b/examples/yolo/darknet.rs @@ -17,7 +17,7 @@ struct Block { impl Block { fn get(&self, key: &str) -> Result<&str> { - match self.parameters.get(&key.to_string()) { + match self.parameters.get(key) { None => bail!("cannot find {} in {}", key, self.block_type), Some(value) => Ok(value), } @@ -32,7 +32,7 @@ pub struct Darknet { impl Darknet { fn get(&self, key: &str) -> Result<&str> { - match self.parameters.get(&key.to_string()) { + match self.parameters.get(key) { None => bail!("cannot find {} in net parameters", key), Some(value) => Ok(value), }