use of com.simiacryptus.mindseye.layers.java.MonitoringWrapperLayer in project MindsEye by SimiaCryptus.
the class TestUtil method extractPerformance.
/**
* Remove performance wrappers.
*
* @param log the log
* @param network the network
*/
public static void extractPerformance(@Nonnull final NotebookOutput log, @Nonnull final DAGNetwork network) {
log.p("Per-layer Performance Metrics:");
log.code(() -> {
@Nonnull final Map<CharSequence, MonitoringWrapperLayer> metrics = new HashMap<>();
network.visitNodes(node -> {
if (node.getLayer() instanceof MonitoringWrapperLayer) {
@Nullable final MonitoringWrapperLayer layer = node.getLayer();
Layer inner = layer.getInner();
String str = inner.toString();
str += " class=" + inner.getClass().getName();
// if(inner instanceof MultiPrecision<?>) {
// str += "; precision=" + ((MultiPrecision) inner).getPrecision().name();
// }
metrics.put(str, layer);
}
});
TestUtil.log.info("Performance: \n\t" + metrics.entrySet().stream().sorted(Comparator.comparing(x -> -x.getValue().getForwardPerformance().getMean())).map(e -> {
@Nonnull final PercentileStatistics performanceF = e.getValue().getForwardPerformance();
@Nonnull final PercentileStatistics performanceB = e.getValue().getBackwardPerformance();
return String.format("%.6fs +- %.6fs (%d) <- %s", performanceF.getMean(), performanceF.getStdDev(), performanceF.getCount(), e.getKey()) + (performanceB.getCount() == 0 ? "" : String.format("%n\tBack: %.6fs +- %.6fs (%s)", performanceB.getMean(), performanceB.getStdDev(), performanceB.getCount()));
}).reduce((a, b) -> a + "\n\t" + b).get());
});
removeInstrumentation(network);
}
use of com.simiacryptus.mindseye.layers.java.MonitoringWrapperLayer in project MindsEye by SimiaCryptus.
the class TestUtil method instrumentPerformance.
/**
* Add performance wrappers.
*
* @param network the network
*/
public static void instrumentPerformance(@Nonnull final DAGNetwork network) {
network.visitNodes(node -> {
Layer layer = node.getLayer();
if (layer instanceof MonitoringWrapperLayer) {
((MonitoringWrapperLayer) layer).shouldRecordSignalMetrics(false);
} else {
@Nonnull MonitoringWrapperLayer monitoringWrapperLayer = new MonitoringWrapperLayer(layer).shouldRecordSignalMetrics(false);
node.setLayer(monitoringWrapperLayer);
monitoringWrapperLayer.freeRef();
}
});
}
use of com.simiacryptus.mindseye.layers.java.MonitoringWrapperLayer in project MindsEye by SimiaCryptus.
the class TestUtil method samplePerformance.
/**
* Sample performance map.
*
* @param network the network
* @return the map
*/
public static Map<CharSequence, Object> samplePerformance(@Nonnull final DAGNetwork network) {
@Nonnull final Map<CharSequence, Object> metrics = new HashMap<>();
network.visitLayers(layer -> {
if (layer instanceof MonitoringWrapperLayer) {
MonitoringWrapperLayer monitoringWrapperLayer = (MonitoringWrapperLayer) layer;
Layer inner = monitoringWrapperLayer.getInner();
String str = inner.toString();
str += " class=" + inner.getClass().getName();
HashMap<CharSequence, Object> row = new HashMap<>();
row.put("fwd", monitoringWrapperLayer.getForwardPerformance().getMetrics());
row.put("rev", monitoringWrapperLayer.getBackwardPerformance().getMetrics());
metrics.put(str, row);
}
});
return metrics;
}
Aggregations