Error: Failed to find 'weight' key in map #1413
-
I encountered an error while trying to load a PyTorch model, despite verifying that all linear layers possess This is my project: https://github.com/zemelLeong/table-structure-recognition All logsthread 'main' panicked at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-import\src\pytorch\adapter.rs:35:14:
Failed to find 'weight' key in map
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:645
1: core::panicking::panic_fmt
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\panicking.rs:72
2: core::panicking::panic_display
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\panicking.rs:178
3: core::panicking::panic_str
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\panicking.rs:152
4: core::option::expect_failed
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\option.rs:1985
5: enum2$ > >::expect >
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\core\src\option.rs:894
6: burn_import::pytorch::adapter::impl$0::adapt_linear >
at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-import\src\pytorch\adapter.rs:33
7: burn_core::record::serde::adapter::BurnModuleAdapter::adapt > >
at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-core\src\record\serde\adapter.rs:18
8: burn_core::record::serde::de::impl$1::deserialize_struct >,burn_core::nn::linear::_::impl$0::deserialize::__Visitor,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::Deserializer,burn_core::record::settings::FullPrecisionSettings>,burn_core::record::serde::de::Deserializer >,core::marker::PhantomData > >,burn_core::nn::linear::LinearRecordItem<
at C:\Users\11989\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.197\src\de\mod.rs:1728
13: serde::de::impls::impl$19::deserialize::impl$0::visit_seq,burn_core::record::settings::FullPrecisionSettings>,burn_core::record::serde::de::VecSeqAccess >,serde::de::impls::impl$19::deserialize::VecVisitor,burn_core::record::settings::FullPrecisionSettings>,burn_core::record::serde::de::Deserializer,burn_core::record::settings::FullPrecisionSettings>,alloc::alloc::Global>,burn_core::record::serde::de::Deserializer >,core::marker::PhantomData > >,alloc::vec::Vec,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::HashMapAccess >,table_structure_recognition::lore_processor::_::impl$0::deseria
at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-core\src\record\serde\de.rs:88
21: table_structure_recognition::lore_processor::_::impl$0::deserialize,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::Deserializer,burn_core::record::settings::FullPrecisionSettings>,burn_core::record::serde::de::Deserializer >,core::marker::PhantomData > >,table_structure_recognition::lore_process
at C:\Users\11989\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.197\src\de\mod.rs:1867
25: table_structure_recognition::lore_processor::_::impl$0::deserialize::impl$2::visit_map,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::HashMapAccess >,table_structure_recognition::lore_processor::_::impl$0::deseria
at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-core\src\record\serde\de.rs:88
27: table_structure_recognition::lore_processor::_::impl$0::deserialize,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::Deserializer,burn_core::record::settings::FullPrecisionSettings>,burn_core::record::serde::de::Deserializer >,core::marker::PhantomData > >,table_structure_recognition::lore_process
at C:\Users\11989\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.197\src\de\mod.rs:1867
31: table_structure_recognition::lore_processor::_::impl$0::deserialize::impl$2::visit_map,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::HashMapAccess >,table_structure_recognition::lore_processor::_::impl$0::deseria
at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-core\src\record\serde\de.rs:88
33: table_structure_recognition::lore_processor::_::impl$0::deserialize,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::Deserializer,burn_core::record::settings::FullPrecisionSettings>,burn_core::record::serde::de::Deserializer >,core::marker::PhantomData > >,table_structure_recognition::lore_process
at C:\Users\11989\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.197\src\de\mod.rs:1867
37: table_structure_recognition::lore_processor::_::impl$0::deserialize::impl$2::visit_map,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::HashMapAccess >,table_structure_recognition::lore_processor::_::impl$0::deseria
at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-core\src\record\serde\de.rs:88
39: table_structure_recognition::lore_processor::_::impl$0::deserialize,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::Deserializer,burn_core::record::settings::FullPrecisionSettings>,burn_core::record::serde::de::Deserializer >,core::marker::PhantomData > >,table_structure_recognition::lore_process
at C:\Users\11989\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.197\src\de\mod.rs:1867
43: table_structure_recognition::lore_processor::_::impl$0::deserialize::impl$2::visit_map,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::HashMapAccess >,table_structure_recognition::lore_processor::_::impl$0::deseria
at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-core\src\record\serde\de.rs:88
45: table_structure_recognition::lore_processor::_::impl$0::deserialize,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::Deserializer,burn_core::record::settings::FullPrecisionSettings>,burn_core::record::serde::de::Deserializer >,core::marker::PhantomData > >,table_structure_recognition::lore_process
at C:\Users\11989\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.197\src\de\mod.rs:1867
49: table_structure_recognition::model_lore::_::impl$0::deserialize::impl$2::visit_map,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::HashMapAccess >,table_structure_recognition::model_lore::_::impl$0::deserialize
at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-core\src\record\serde\de.rs:88
51: table_structure_recognition::model_lore::_::impl$0::deserialize,burn_core::record::settings::FullPrecisionSettings,burn_core::record::serde::de::Deserializer,burn_core::record::settings::FullPrecisionSettings>,burn_ndarray::b
at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-import\src\pytorch\reader.rs:60
53: burn_import::pytorch::recorder::impl$0::load,table_structure_recognition::model_lore::LoreModelRecord > >
at C:\Users\11989\.cargo\git\checkouts\burn-178c6829f420dae1\2cc39f0\crates\burn-import\src\pytorch\recorder.rs:47
54: table_structure_recognition::model_lore::LoreModel >::new >
at .\src\model_lore.rs:39
55: table_structure_recognition::main
at .\src\main.rs:12
56: core::ops::function::FnOnce::call_once >
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\core\src\ops\function.rs:250
57: core::hint::black_box
at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\core\src\hint.rs:286
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
It seems that this is not a specific issue, there are many similar problems |
Beta Was this translation helpful? Give feedback.
-
I downloaded the pytorch model and your code. Here are my comments
Here is a patch I used to print the keys. We should probably provide some mechanism to print them. Issue ticket: #1416 [burn]% git diff
diff --git a/crates/burn-import/src/pytorch/reader.rs b/crates/burn-import/src/pytorch/reader.rs
index 61e62e8a..6e575575 100644
--- a/crates/burn-import/src/pytorch/reader.rs
+++ b/crates/burn-import/src/pytorch/reader.rs
@@ -47,8 +47,18 @@ where
.map(|(key, tensor)| (key, CandleTensor(tensor)))
.collect();
+ println!("SOURCE KEYS");
+ let mut keys: Vec<String> = tensors.keys().cloned().collect();
+ keys.sort();
+ keys.iter().for_each(|k| println!("{}", k));
+
// Remap the keys (replace the keys in the map with the new keys)
let tensors = remap(tensors, key_remap);
+ println!("==================================================================================================");
+ println!("REMAPPED KEYS");
+ let mut keys: Vec<String> = tensors.keys().cloned().collect();
+ keys.sort();
+ keys.iter().for_each(|k| println!("{}", k));
// Convert the vector of Candle tensors to a nested value data structure
let nested_value = unflatten::<PS, _>(tensors)?;
[burn]% |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I submitted a PR (#1425) to improve the usability and debugging. Now, you can print key/remapped keys/tensor shape and dtypes. |
Beta Was this translation helpful? Give feedback.
I submitted a PR (#1425) to improve the usability and debugging. Now, you can print key/remapped keys/tensor shape and dtypes.