public void init() { if (gradientUpdater == null) { ParamState varState = layersAndVariablesInBlock.get(0); String varName = varState.getParamName(); gradientUpdater = varState.getLayer().conf().getLayer().getIUpdaterByParam(varName).instantiate(updaterView, updaterViewRequiresInitialization); //UpdaterUtils.getGradientUpdater(varState.getLayer(), varState.getParamName()); } }
public static boolean updaterConfigurationsEquals(Layer layer1, String param1, Layer layer2, String param2) { org.deeplearning4j.nn.conf.layers.Layer l1 = layer1.conf().getLayer(); org.deeplearning4j.nn.conf.layers.Layer l2 = layer2.conf().getLayer(); IUpdater u1 = l1.getIUpdaterByParam(param1); IUpdater u2 = l2.getIUpdaterByParam(param2); if (!u1.equals(u2)) { //Different updaters or different config return false; } //For updaters to be equal (and hence combinable), we require that: //(a) The updater-specific configurations are equal (inc. LR) //(b) The learning rate *schedules* are equal //(c) If one or more of the params are pretrainable params, they are in the same layer // This last point is necessary as we don't want to modify the pretrain gradient/updater state during // backprop, or modify the pretrain gradient/updater state of one layer while training another if (!lrSchedulesEqual(layer1, param1, layer2, param2)) { return false; } boolean isPretrainParam1 = layer1.conf().getLayer().isPretrainParam(param1); boolean isPretrainParam2 = layer2.conf().getLayer().isPretrainParam(param2); if (isPretrainParam1 || isPretrainParam2) { //One or both of params are pretrainable. //Either layers differ -> don't want to combine a pretrain updaters across layers //Or one is pretrain and the other isn't -> don't want to combine pretrain updaters within a layer return layer1 == layer2 && isPretrainParam1 && isPretrainParam2; } return true; }
String var = variables.get(j); int paramSizeThisVariable = layerParamTable.get(var).length(); int updaterStateSizeThisVariable = (int) layers[i].conf().getLayer().getIUpdaterByParam(var) .stateSize(paramSizeThisVariable);
/** * Fit the model * * @param input the examples to classify (one example in each row) * @param labels the example labels(a binary outcome matrix) */ @Override public void fit(INDArray input, INDArray labels) { setInput(input); setLabels(labels); applyDropOutIfNecessary(true); if (solver == null) { solver = new Solver.Builder().configure(conf()).listeners(getListeners()).model(this).build(); //Set the updater state view array. For MLN and CG, this is done by MultiLayerUpdater and ComputationGraphUpdater respectively Updater updater = solver.getOptimizer().getUpdater(); int updaterStateSize = 0; Map<String, INDArray> paramTable = paramTable(); for (Map.Entry<String, INDArray> entry : paramTable.entrySet()) { updaterStateSize += (int) conf().getLayer().getIUpdaterByParam(entry.getKey()) .stateSize(entry.getValue().length()); } if (updaterStateSize > 0) updater.setStateViewArray(this, Nd4j.createUninitialized(new int[] {1, updaterStateSize}, Nd4j.order()), true); } solver.optimize(); }