Skip to content

Commit

Permalink
Auto merge of #87 - alexandermorozov:fix-sgd-init, r=hobofan
Browse files Browse the repository at this point in the history
fix/sgd: initialize weight gradient history with zeroes

SGD solver used unintialized history tensors. If there were some NaNs then
whole network got poisoned after the first generation even if momentum
was set to zero. This patch prefills gradient history with zeros.

FIX: autumnai/leaf-examples#13
  • Loading branch information
homu committed Mar 23, 2016
2 parents 6f41247 + 6868995 commit 3b25a48
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/solvers/sgd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ macro_rules! impl_isolver_sgd {

for weight_gradient in net.learnable_weights_gradients() {
let shape = weight_gradient.read().unwrap().desc().clone();
let history_tensor = Arc::new(RwLock::new(SharedTensor::new(IBackend::device(&*self.backend), &shape).unwrap()));
let mut tensor = SharedTensor::new(IBackend::device(&*self.backend),
&shape).unwrap();

let filler = ::weight::FillerType::Constant { value: 0f32 };
filler.fill(&mut tensor);

let history_tensor = Arc::new(RwLock::new(tensor));
self.history.push(history_tensor);
}
}
Expand Down

0 comments on commit 3b25a48

Please sign in to comment.