Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some better error messages #189

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions juice/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,22 @@ impl<B: IBackend> Layer<B> {
// reshape input tensor to the reshaped shape
let old_shape = self.input_blobs_data[input_i].read().unwrap().desc().clone();
if old_shape.size() != reshaped_shape.size() {
panic!(
"Input Shape Mismatch\nExpected {:?}\nActual {:?}",
reshaped_shape, old_shape
);
if reshaped_shape[1..] == old_shape[1..] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd make more sense to add an assert per dimension, and just fail with the first.

for dim in 0..5 {
     let old = old_shape[dim];
     let reshaped = reshaped__shape[dim];
     assert_eq!(old, reshpaed, "Dimension {dim} mismatches {old} != {reshaped}"); 
}
unreachable!("If the total size is not equal, one dimension mismatch must exist. qed");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it this way to catch some errors with mismatched batch sizes to make it a bit more clear.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should always show the full dimensions as well. That way it stays clear where it could originate from your code. These errors can arise from rather deep inside the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that my recent commit should have done this.

eprintln!("Expected batch size {} but got batch size {}.", reshaped_shape[0], old_shape[0]);
}
else if reshaped_shape[1..] == old_shape {
eprintln!("Expected batch size {} but got batch size {}.", reshaped_shape[0], 1);
}
else {
eprintln!(
"Input Shape Mismatch at layer {}\nLayer has input shape {:?}\nInput given has shape {:?}",
self.name, reshaped_shape, old_shape
);
}
if reshaped_shape == old_shape[1..] {
eprintln!("You may have forgotten to specify a batch size in your model input.");
}
panic!();
}
self.input_blobs_data[input_i]
.write()
Expand Down
3 changes: 3 additions & 0 deletions juice/src/layers/common/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ impl<B: IBackend + LayerOps<f32>> ILayer<B> for Linear {
output_data: &mut Vec<ArcLock<SharedTensor<f32>>>,
output_gradient: &mut Vec<ArcLock<SharedTensor<f32>>>,
) {
if input_data.len() == 0 {
panic!("Linear layer expected input, but none was given.");
}
let input = input_data[0].read().unwrap();
let batch_size = input.desc()[0];
// reshape top
Expand Down
3 changes: 3 additions & 0 deletions juice/src/layers/container/sequential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ impl<B: IBackend + LayerOps<f32> + 'static> ILayer<B> for Sequential<B> {
output_data: &mut [ArcLock<SharedTensor<f32>>],
) {
for layer in &self.layers {
if layer.borrow().input_blob_names.len() < input_data.len() {
panic!("Layer {} expected {} input(s) but got {}.", layer.borrow().name, layer.borrow().input_blob_names.len(), input_data.len());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

for (i, (input, input_name)) in input_data.iter().zip(self.input_tensor_names.iter()).enumerate() {
if &layer.borrow().input_blob_names[i] == input_name {
layer.borrow_mut().input_blobs_data[i] = input.clone();
Expand Down