More smart incremental recalculation

For example, when using Keras to train a CNN model,
I only changed some string in print statements,
but it triggers rerunning of the whole (slow) training process.

score = model.evaluate(x_test, y_test, verbose=0)
print('test loss:', score[0])
print('test accuracy:', score[1])

Just changing test to Test in print string will trigger rerunning of the whole training process.

May more smart static analysis be applied?

Even if we’d have the smartest static analysis that won’t help us in this case. Because block is an atomic unit of computation and it’s indivisible. There is no way to replace one statement:

print('test accuracy:', score[1])

with

print('Test accuracy:', score[1])

In general I would suggest to always keep computation-heavy code like training in a separate block. In your case it’s better to split block like this:

score = model.evaluate(x_test, y_test, verbose=0)
-----------------------------
print('test loss:', score[0])
print('test accuracy:', score[1])
1 Like