title: How to calculate optimal batch size
body: <p>Sometimes I run into a problem:</p>
  <pre><code>OOM when allocating tensor with shape
  </code></pre>
  <p>e.g.</p>
  <pre><code>OOM when allocating tensor with shape (1024, 100, 160)
  </code></pre>
  <p>Where 1024 is my batch size and I don't know what's the rest. If I reduce the batch size or the number of neurons in the model, it runs fine.</p>
  <p>Is there a generic way to calculate optimal batch size based on model and GPU memory, so the program doesn't crash?</p>
  <p>In short: I want the largest batch size possible in terms of my model, which will fit into my GPU memory and won't crash the program.</p>