Hi,
The error is that you run out of memory.
I guess your script when using the l2 norm is using almost all the memory.
Your implementation has intermediary results (and so uses a bit more memory).
I guess reducing your batch size should reduce the memory footprint and make it run nicely.