huggingface / candle

Minimalist ML framework for Rust
Apache License 2.0
15.76k stars 943 forks source link

Trainable maxpool where kernel size != stride #1593

Open Awpteamoose opened 9 months ago

Awpteamoose commented 9 months ago

I'm trying to port a text detection model from PyTorch. It has a particular layer:

nn.MaxPool2d(kernel_size=3, stride=1, padding=1)

which I have ported like so:

let xs = xs.pad_with_zeros(2, 1, 1)?.pad_with_zeros(3, 1, 1)?;
let xs = xs.max_pool2d_with_stride(3, 1)?;

(I know I'm meant to pad with -inf but I was just checking if it would even start training)

I got the error:

thread 'main' panicked at src\main.rs:111:48:
called Result::unwrap() on an Err value: Msg("backward not supported for maxpool2d if ksize (3, 3) != stride (1, 1)")
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
chenwanqq commented 9 months ago

that is a serious problem. I try to write a demo to train resnet but it can't work because of this error.

asukaminato0721 commented 4 months ago

oh, I meet the same problem.

https://github.com/asukaminato0721/d2l.ai-rs/blob/87e5614e9920fd1501076c1145a1ea8a3efdda8c/src/ch8/ch8_4.rs#L65

asukaminato0721 commented 4 months ago

that is a serious problem. I try to write a demo to train resnet but it can't work because of this error.

here is an example https://github.com/huggingface/candle/blob/main/candle-transformers/src/models/resnet.rs