tracel-ai / models

Models and examples built with Burn
Apache License 2.0
180 stars 24 forks source link

Running non-release build causes a crash for resnet-burn inference example #36

Closed JeremyBYU closed 1 month ago

JeremyBYU commented 4 months ago

Hi all, I was testing out this project and noticed that when I run cargo run --example inference --features tch-gpu ./samples/dog.jpg it causes a crash with the error: unsafe precondition(s) violated: ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap. However, if I run with --release everything works as expected. Not sure if this was as designed and if so was wondering the reasoning. Thanks

❯ RUST_BACKTRACE=1 cargo run --example inference --features tch-gpu ./samples/dog.jpg
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/examples/inference ./samples/dog.jpg`
thread 'main' panicked at library/core/src/panicking.rs:220:5:
unsafe precondition(s) violated: ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap
stack backtrace:
   0: rust_begin_unwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:110:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:120:5
   3: core::panicking::panic_nounwind
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:220:5
   4: core::intrinsics::copy_nonoverlapping::precondition_check
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ub_checks.rs:66:21
   5: core::intrinsics::copy_nonoverlapping
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ub_checks.rs:73:17
   6: <burn_core::record::serde::de::Deserializer<A> as serde::de::Deserializer>::deserialize_enum::clone_unsafely
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-core-0.13.2/src/record/serde/de.rs:355:17
   7: <burn_core::record::serde::de::Deserializer<A> as serde::de::Deserializer>::deserialize_enum
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-core-0.13.2/src/record/serde/de.rs:364:34
   8: resnet_burn::block::_::<impl serde::de::Deserialize for resnet_burn::block::ResidualBlockRecordItem<B,S>>::deserialize
             at ./resnet/src/block.rs:15:10
   9: <core::marker::PhantomData<T> as serde::de::DeserializeSeed>::deserialize
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.203/src/de/mod.rs:794:9
  10: <burn_core::record::serde::de::VecSeqAccess<A> as serde::de::SeqAccess>::next_element_seed
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-core-0.13.2/src/record/serde/de.rs:420:9
  11: serde::de::SeqAccess::next_element
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.203/src/de/mod.rs:1728:9
  12: <serde::de::impls::<impl serde::de::Deserialize for alloc::vec::Vec<T>>::deserialize::VecVisitor<T> as serde::de::Visitor>::visit_seq
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.203/src/de/impls.rs:1175:46
  13: <burn_core::record::serde::de::Deserializer<A> as serde::de::Deserializer>::deserialize_seq
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-core-0.13.2/src/record/serde/de.rs:290:13
  14: serde::de::impls::<impl serde::de::Deserialize for alloc::vec::Vec<T>>::deserialize
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.203/src/de/impls.rs:1186:9
  15: <core::marker::PhantomData<T> as serde::de::DeserializeSeed>::deserialize
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.203/src/de/mod.rs:794:9
  16: <burn_core::record::serde::de::HashMapAccess<A> as serde::de::MapAccess>::next_value_seed
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-core-0.13.2/src/record/serde/de.rs:477:24
  17: serde::de::MapAccess::next_value
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.203/src/de/mod.rs:1867:9
  18: <resnet_burn::block::_::<impl serde::de::Deserialize for resnet_burn::block::LayerBlockRecordItem<B,S>>::deserialize::__Visitor<B,S> as serde::de::Visitor>::visit_map
             at ./resnet/src/block.rs:153:10
  19: <burn_core::record::serde::de::Deserializer<A> as serde::de::Deserializer>::deserialize_struct
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-core-0.13.2/src/record/serde/de.rs:90:17
  20: resnet_burn::block::_::<impl serde::de::Deserialize for resnet_burn::block::LayerBlockRecordItem<B,S>>::deserialize
             at ./resnet/src/block.rs:153:10
  21: <core::marker::PhantomData<T> as serde::de::DeserializeSeed>::deserialize
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.203/src/de/mod.rs:794:9
  22: <burn_core::record::serde::de::HashMapAccess<A> as serde::de::MapAccess>::next_value_seed
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-core-0.13.2/src/record/serde/de.rs:477:24
  23: serde::de::MapAccess::next_value
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.203/src/de/mod.rs:1867:9
  24: <resnet_burn::resnet::_::<impl serde::de::Deserialize for resnet_burn::resnet::ResNetRecordItem<B,S>>::deserialize::__Visitor<B,S> as serde::de::Visitor>::visit_map
             at ./resnet/src/resnet.rs:31:10
  25: <burn_core::record::serde::de::Deserializer<A> as serde::de::Deserializer>::deserialize_struct
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-core-0.13.2/src/record/serde/de.rs:90:17
  26: resnet_burn::resnet::_::<impl serde::de::Deserialize for resnet_burn::resnet::ResNetRecordItem<B,S>>::deserialize
             at ./resnet/src/resnet.rs:31:10
  27: burn_import::pytorch::reader::from_file
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-import-0.13.2/src/pytorch/reader.rs:82:17
  28: <burn_import::pytorch::recorder::PyTorchFileRecorder<PS> as burn_core::record::recorder::Recorder<B>>::load
             at /home/jeremy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/burn-import-0.13.2/src/pytorch/recorder.rs:47:20
  29: resnet_burn::resnet::ResNet<B>::load_weights_record
             at ./resnet/src/resnet.rs:279:22
  30: resnet_burn::resnet::ResNet<B>::resnet18_pretrained
             at ./resnet/src/resnet.rs:97:22
  31: inference::main
             at ./examples/inference/examples/inference.rs:34:9
  32: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread caused non-unwinding panic. aborting.
zsh: abort (core dumped)  RUST_BACKTRACE=1 cargo run --example inference --features tch-gpu 

With Release:

❯ cargo run --release --example inference --features tch-gpu ./samples/dog.jpg     
    Finished `release` profile [optimized] target(s) in 0.13s
     Running `target/release/examples/inference ./samples/dog.jpg`
Predicted: Labrador retriever
Category Id: 208
Score: 14.4482
antimora commented 4 months ago

This is caused by the new rust version. This is fixed on Burn main. Not released yet.

liuhuapiaoyuan commented 1 month ago

When can it be updated, I also encountered this problem when running yolo-tiny, and it's normal once I use release

laggui commented 1 month ago

ResNet was recently updated in #40 to use the latest burn release, it should be fixed.

Just updated YOLOX in #41 to make sure this is addressed.

Let me know if you're still facing the same issue.