Skip to content

Commit d96bb45

Browse files
Merge pull request #940 from LaurentMazare/pytorch-2.7.0
Update for PyTorch 2.7.0.
2 parents efae36c + 6637202 commit d96bb45

File tree

13 files changed

+245
-39
lines changed

13 files changed

+245
-39
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## Unreleased
88
### Changed
99

10+
## v0.20.0
11+
### Changed
12+
- PyTorch v2.7 support
13+
1014
## v0.19.0
1115
### Changed
1216
- PyTorch v2.6 support

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tch"
3-
version = "0.19.0"
3+
version = "0.20.0"
44
authors = ["Laurent Mazare <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"
@@ -22,7 +22,7 @@ libc = "0.2.0"
2222
ndarray = "0.16.1"
2323
rand = "0.8"
2424
thiserror = "1"
25-
torch-sys = { version = "0.19.0", path = "torch-sys" }
25+
torch-sys = { version = "0.20.0", path = "torch-sys" }
2626
zip = "0.6"
2727
half = "2"
2828
safetensors = "0.3.0"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The code generation part for the C api on top of libtorch comes from
1818

1919
## Getting Started
2020

21-
This crate requires the C++ PyTorch library (libtorch) in version *v2.6.0* to be available on
21+
This crate requires the C++ PyTorch library (libtorch) in version *v2.7.0* to be available on
2222
your system. You can either:
2323

2424
- Use the system-wide libtorch installation (default).
@@ -85,7 +85,7 @@ seem to include `libtorch.a` by default so this would have to be compiled
8585
manually, e.g. via the following:
8686

8787
```bash
88-
git clone -b v2.6.0 --recurse-submodule https://github.com/pytorch/pytorch.git pytorch-static --depth 1
88+
git clone -b v2.7.0 --recurse-submodule https://github.com/pytorch/pytorch.git pytorch-static --depth 1
8989
cd pytorch-static
9090
USE_CUDA=OFF BUILD_SHARED_LIBS=OFF python setup.py build
9191
# export LIBTORCH to point at the build directory in pytorch-static.

examples/python-extension/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tch-ext"
3-
version = "0.2.0"
3+
version = "0.20.0"
44
authors = ["Laurent Mazare <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"
@@ -18,6 +18,6 @@ crate-type = ["cdylib"]
1818

1919
[dependencies]
2020
pyo3 = { version = "0.24", features = ["extension-module"] }
21-
pyo3-tch = { path = "../../pyo3-tch", version = "0.19.0" }
22-
tch = { path = "../..", features = ["python-extension"], version = "0.19.0" }
23-
torch-sys = { path = "../../torch-sys", features = ["python-extension"], version = "0.19.0" }
21+
pyo3-tch = { path = "../../pyo3-tch", version = "0.20.0" }
22+
tch = { path = "../..", features = ["python-extension"], version = "0.20.0" }
23+
torch-sys = { path = "../../torch-sys", features = ["python-extension"], version = "0.20.0" }

gen/gen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ let run
883883

884884
let () =
885885
run
886-
~yaml_filename:"third_party/pytorch/Declarations-v2.6.0.yaml"
886+
~yaml_filename:"third_party/pytorch/Declarations-v2.7.0.yaml"
887887
~cpp_filename:"torch-sys/libtch/torch_api_generated"
888888
~ffi_filename:"torch-sys/src/c_generated.rs"
889889
~wrapper_filename:"src/wrappers/tensor_generated.rs"

pyo3-tch/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyo3-tch"
3-
version = "0.19.0"
3+
version = "0.20.0"
44
authors = ["Laurent Mazare <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"
@@ -12,6 +12,6 @@ categories = ["science"]
1212
license = "MIT/Apache-2.0"
1313

1414
[dependencies]
15-
tch = { path = "..", features = ["python-extension"], version = "0.19.0" }
16-
torch-sys = { path = "../torch-sys", features = ["python-extension"], version = "0.19.0" }
17-
pyo3 = { version = "0.24", features = ["extension-module"] }
15+
tch = { path = "..", features = ["python-extension"], version = "0.20.0" }
16+
torch-sys = { path = "../torch-sys", features = ["python-extension"], version = "0.20.0" }
17+
pyo3 = { version = "0.24", features = ["extension-module"] }

src/wrappers/tensor_fallible_generated.rs

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,46 @@ impl Tensor {
20602060
Ok(Tensor { c_tensor: c_tensors[0] })
20612061
}
20622062

2063+
pub fn f_internal_dyn_quant_matmul_4bit(
2064+
inp: &Tensor,
2065+
packed_weights: &Tensor,
2066+
block_size: i64,
2067+
in_features: i64,
2068+
out_features: i64,
2069+
) -> Result<Tensor, TchError> {
2070+
let mut c_tensors = [std::ptr::null_mut(); 1];
2071+
unsafe_torch_err!(atg__dyn_quant_matmul_4bit(
2072+
c_tensors.as_mut_ptr(),
2073+
inp.c_tensor,
2074+
packed_weights.c_tensor,
2075+
block_size,
2076+
in_features,
2077+
out_features
2078+
));
2079+
Ok(Tensor { c_tensor: c_tensors[0] })
2080+
}
2081+
2082+
pub fn f_internal_dyn_quant_pack_4bit_weight<T: Borrow<Tensor>>(
2083+
weights: &Tensor,
2084+
scales_zeros: &Tensor,
2085+
bias: Option<T>,
2086+
block_size: i64,
2087+
in_features: i64,
2088+
out_features: i64,
2089+
) -> Result<Tensor, TchError> {
2090+
let mut c_tensors = [std::ptr::null_mut(); 1];
2091+
unsafe_torch_err!(atg__dyn_quant_pack_4bit_weight(
2092+
c_tensors.as_mut_ptr(),
2093+
weights.c_tensor,
2094+
scales_zeros.c_tensor,
2095+
bias.as_ref().map_or(std::ptr::null_mut(), |t| t.borrow().c_tensor),
2096+
block_size,
2097+
in_features,
2098+
out_features
2099+
));
2100+
Ok(Tensor { c_tensor: c_tensors[0] })
2101+
}
2102+
20632103
pub fn f_internal_efficient_attention_backward<T: Borrow<Tensor>>(
20642104
grad_out_: &Tensor,
20652105
query: &Tensor,
@@ -2900,8 +2940,8 @@ impl Tensor {
29002940
max_k: i64,
29012941
dropout_p: f64,
29022942
is_causal: bool,
2903-
philox_seed: &Tensor,
2904-
philox_offset: &Tensor,
2943+
rng_state: &Tensor,
2944+
unused: &Tensor,
29052945
scale: impl Into<Option<f64>>,
29062946
window_size_left: impl Into<Option<i64>>,
29072947
window_size_right: impl Into<Option<i64>>,
@@ -2924,8 +2964,8 @@ impl Tensor {
29242964
max_k,
29252965
dropout_p,
29262966
if is_causal { 1 } else { 0 },
2927-
philox_seed.c_tensor,
2928-
philox_offset.c_tensor,
2967+
rng_state.c_tensor,
2968+
unused.c_tensor,
29292969
scale.unwrap_or(std::f64::NAN),
29302970
scale.is_none() as i8,
29312971
window_size_left.unwrap_or(0i64),
@@ -5783,6 +5823,33 @@ impl Tensor {
57835823
))
57845824
}
57855825

5826+
pub fn f_internal_scaled_grouped_mm<T: Borrow<Tensor>>(
5827+
&self,
5828+
mat2: &Tensor,
5829+
scale_a: &Tensor,
5830+
scale_b: &Tensor,
5831+
offs: Option<T>,
5832+
bias: Option<T>,
5833+
scale_result: Option<T>,
5834+
out_dtype: impl Into<Option<Kind>>,
5835+
use_fast_accum: bool,
5836+
) -> Result<Tensor, TchError> {
5837+
let mut c_tensors = [std::ptr::null_mut(); 1];
5838+
unsafe_torch_err!(atg__scaled_grouped_mm(
5839+
c_tensors.as_mut_ptr(),
5840+
self.c_tensor,
5841+
mat2.c_tensor,
5842+
scale_a.c_tensor,
5843+
scale_b.c_tensor,
5844+
offs.as_ref().map_or(std::ptr::null_mut(), |t| t.borrow().c_tensor),
5845+
bias.as_ref().map_or(std::ptr::null_mut(), |t| t.borrow().c_tensor),
5846+
scale_result.as_ref().map_or(std::ptr::null_mut(), |t| t.borrow().c_tensor),
5847+
out_dtype.into().map_or(-1, |s| s.c_int()),
5848+
if use_fast_accum { 1 } else { 0 }
5849+
));
5850+
Ok(Tensor { c_tensor: c_tensors[0] })
5851+
}
5852+
57865853
pub fn f_internal_scaled_mm<T: Borrow<Tensor>>(
57875854
&self,
57885855
mat2: &Tensor,
@@ -35234,6 +35301,7 @@ impl Tensor {
3523435301
normalized: bool,
3523535302
onesided: bool,
3523635303
return_complex: bool,
35304+
align_to_window: bool,
3523735305
) -> Result<Tensor, TchError> {
3523835306
let hop_length = hop_length.into();
3523935307
let win_length = win_length.into();
@@ -35249,7 +35317,8 @@ impl Tensor {
3524935317
window.as_ref().map_or(std::ptr::null_mut(), |t| t.borrow().c_tensor),
3525035318
if normalized { 1 } else { 0 },
3525135319
if onesided { 1 } else { 0 },
35252-
if return_complex { 1 } else { 0 }
35320+
if return_complex { 1 } else { 0 },
35321+
if align_to_window { 1 } else { 0 }
3525335322
));
3525435323
Ok(Tensor { c_tensor: c_tensors[0] })
3525535324
}
@@ -35265,6 +35334,7 @@ impl Tensor {
3526535334
normalized: bool,
3526635335
onesided: bool,
3526735336
return_complex: bool,
35337+
align_to_window: bool,
3526835338
) -> Result<Tensor, TchError> {
3526935339
let hop_length = hop_length.into();
3527035340
let win_length = win_length.into();
@@ -35283,7 +35353,8 @@ impl Tensor {
3528335353
pad_mode.len() as i32,
3528435354
if normalized { 1 } else { 0 },
3528535355
if onesided { 1 } else { 0 },
35286-
if return_complex { 1 } else { 0 }
35356+
if return_complex { 1 } else { 0 },
35357+
if align_to_window { 1 } else { 0 }
3528735358
));
3528835359
Ok(Tensor { c_tensor: c_tensors[0] })
3528935360
}

src/wrappers/tensor_generated.rs

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,42 @@ impl Tensor {
12311231
Tensor::f_internal_dirichlet_grad_out(out, x, alpha, total).unwrap()
12321232
}
12331233

1234+
pub fn internal_dyn_quant_matmul_4bit(
1235+
inp: &Tensor,
1236+
packed_weights: &Tensor,
1237+
block_size: i64,
1238+
in_features: i64,
1239+
out_features: i64,
1240+
) -> Tensor {
1241+
Tensor::f_internal_dyn_quant_matmul_4bit(
1242+
inp,
1243+
packed_weights,
1244+
block_size,
1245+
in_features,
1246+
out_features,
1247+
)
1248+
.unwrap()
1249+
}
1250+
1251+
pub fn internal_dyn_quant_pack_4bit_weight<T: Borrow<Tensor>>(
1252+
weights: &Tensor,
1253+
scales_zeros: &Tensor,
1254+
bias: Option<T>,
1255+
block_size: i64,
1256+
in_features: i64,
1257+
out_features: i64,
1258+
) -> Tensor {
1259+
Tensor::f_internal_dyn_quant_pack_4bit_weight(
1260+
weights,
1261+
scales_zeros,
1262+
bias,
1263+
block_size,
1264+
in_features,
1265+
out_features,
1266+
)
1267+
.unwrap()
1268+
}
1269+
12341270
pub fn internal_efficient_attention_backward<T: Borrow<Tensor>>(
12351271
grad_out_: &Tensor,
12361272
query: &Tensor,
@@ -1856,8 +1892,8 @@ impl Tensor {
18561892
max_k: i64,
18571893
dropout_p: f64,
18581894
is_causal: bool,
1859-
philox_seed: &Tensor,
1860-
philox_offset: &Tensor,
1895+
rng_state: &Tensor,
1896+
unused: &Tensor,
18611897
scale: impl Into<Option<f64>>,
18621898
window_size_left: impl Into<Option<i64>>,
18631899
window_size_right: impl Into<Option<i64>>,
@@ -1875,8 +1911,8 @@ impl Tensor {
18751911
max_k,
18761912
dropout_p,
18771913
is_causal,
1878-
philox_seed,
1879-
philox_offset,
1914+
rng_state,
1915+
unused,
18801916
scale,
18811917
window_size_left,
18821918
window_size_right,
@@ -3488,6 +3524,30 @@ impl Tensor {
34883524
.unwrap()
34893525
}
34903526

3527+
pub fn internal_scaled_grouped_mm<T: Borrow<Tensor>>(
3528+
&self,
3529+
mat2: &Tensor,
3530+
scale_a: &Tensor,
3531+
scale_b: &Tensor,
3532+
offs: Option<T>,
3533+
bias: Option<T>,
3534+
scale_result: Option<T>,
3535+
out_dtype: impl Into<Option<Kind>>,
3536+
use_fast_accum: bool,
3537+
) -> Tensor {
3538+
self.f_internal_scaled_grouped_mm(
3539+
mat2,
3540+
scale_a,
3541+
scale_b,
3542+
offs,
3543+
bias,
3544+
scale_result,
3545+
out_dtype,
3546+
use_fast_accum,
3547+
)
3548+
.unwrap()
3549+
}
3550+
34913551
pub fn internal_scaled_mm<T: Borrow<Tensor>>(
34923552
&self,
34933553
mat2: &Tensor,
@@ -17844,9 +17904,19 @@ impl Tensor {
1784417904
normalized: bool,
1784517905
onesided: bool,
1784617906
return_complex: bool,
17907+
align_to_window: bool,
1784717908
) -> Tensor {
17848-
self.f_stft(n_fft, hop_length, win_length, window, normalized, onesided, return_complex)
17849-
.unwrap()
17909+
self.f_stft(
17910+
n_fft,
17911+
hop_length,
17912+
win_length,
17913+
window,
17914+
normalized,
17915+
onesided,
17916+
return_complex,
17917+
align_to_window,
17918+
)
17919+
.unwrap()
1785017920
}
1785117921

1785217922
pub fn stft_center<T: Borrow<Tensor>>(
@@ -17860,6 +17930,7 @@ impl Tensor {
1786017930
normalized: bool,
1786117931
onesided: bool,
1786217932
return_complex: bool,
17933+
align_to_window: bool,
1786317934
) -> Tensor {
1786417935
self.f_stft_center(
1786517936
n_fft,
@@ -17871,6 +17942,7 @@ impl Tensor {
1787117942
normalized,
1787217943
onesided,
1787317944
return_complex,
17945+
align_to_window,
1787417946
)
1787517947
.unwrap()
1787617948
}

torch-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "torch-sys"
3-
version = "0.19.0"
3+
version = "0.20.0"
44
authors = ["Laurent Mazare <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"

0 commit comments

Comments
 (0)