Pytorch_cuda_alloc_conf

mark87: <p>I understand the meaning of this command (PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:516), but where do you actually write it?<br>
In jupyter notebook? In command prompt?</p>

ptrblck: <p><code>export</code> it as an env variable in your terminal and it should work.</p>

mark87: <p>Thank you for the answer, but now I am even more confused where should I write what. <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>

gahaalt: <p>You can set environment variables directly from Python:</p>
<pre><code class="lang-auto">import os

os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:516"
</code></pre>
<p>This must be executed at the beginning of your script/notebook.</p>

mark87: <aside class="quote no-group" data-username="gahaalt" data-post="5" data-topic="165376">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/gahaalt/48/53985_2.png" class="avatar"> gahaalt:</div>
<blockquote>
<pre><code class="lang-auto">import os

os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:516"
</code></pre>
</blockquote>
</aside>
<p>Many thanks! <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>

mark87: <p>Didn’t work. Still get CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 6.00 GiB total capacity; 5.33 GiB already  allocated; 0 bytes free; 5.34 GiB reserved in total by PyTorch)</p>

z290048663: <p>First, use  the method mentioned above.<br>
in the linux terminal, you can input the command:</p>
<p><code>export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512</code></p>
<p>Second,<br>
you can try --tile following your command.<br>
"decrease the --tile</p>
<p>such as --tile 800 or smaller than 800"</p>
<aside class="onebox githubissue" data-onebox-src="https://github.com/xinntao/Real-ESRGAN/issues/101">
  <header class="source">

      <a href="https://github.com/xinntao/Real-ESRGAN/issues/101" target="_blank" rel="noopener nofollow ugc">github.com/xinntao/Real-ESRGAN</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewbox="0 0 14 16" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/xinntao/Real-ESRGAN/issues/101" target="_blank" rel="noopener nofollow ugc">CUDA out of memory</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2021-09-27" data-time="14:18:37" data-timezone="UTC">02:18PM - 27 Sep 21 UTC</span>
      </div>

        <div class="date">
          closed <span class="discourse-local-date" data-format="ll" data-date="2021-09-29" data-time="00:20:22" data-timezone="UTC">12:20AM - 29 Sep 21 UTC</span>
        </div>

      <div class="user">
        <a href="https://github.com/TornaxO7" target="_blank" rel="noopener nofollow ugc">
          <img alt="TornaxO7" src="https://avatars.githubusercontent.com/u/50843046?v=4" class="onebox-avatar-inline" width="20" height="20">
          TornaxO7
        </a>
      </div>
    </div>

    <div class="labels">
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">Thank you first of all for this awesome program!

I'm getting the following er<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">ror message if I run your program:
```
Testing 0 place
/home/tornax/Apps/Real-ESRGAN/inference_realesrgan.py:84: UserWarning: The input image is large, try X2 model for better performance.
  warnings.warn('The input image is large, try X2 model for better performance.')
Error CUDA out of memory. Tried to allocate 1.20 GiB (GPU 0; 3.94 GiB total capacity; 1.54 GiB already allocated; 1.22 GiB free; 1.74 GiB reserved in total by PyTorch)
	Tile 1/1
Error local variable 'output_tile' referenced before assignment
If you encounter CUDA out of memory, try to set --tile with a smaller number.
```

I have 12GB of RAM and it's fine for me if it's using all of it. How can I set the allowed RAM usage?
I've tried to call it like this:
```
python inference_realesrgan.py --tile 12000000 --model_path experiments/pretrained_models/RealESRGAN_x4plus_anime_6B.pth --input inputs --outscale 0 ```
but it doesn't work as well (I get the same error message).</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
<p>
eg.</p>
<pre><code class="lang-auto">python inference_realesrgan.py --tile 120
</code></pre>
<p>I’ve tried these 2 steps, and it works for me.<br>
My Chinese blog:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://blog.csdn.net/z290048663/article/details/128950092?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22128950092%22%2C%22source%22%3A%22z290048663%22%7D">
  <header class="source">
      <img src="https://g.csdnimg.cn/static/logo/favicon32.ico" class="site-icon" width="32" height="32">

      <a href="https://blog.csdn.net/z290048663/article/details/128950092?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22128950092%22%2C%22source%22%3A%22z290048663%22%7D" target="_blank" rel="noopener nofollow ugc">blog.csdn.net</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://blog.csdn.net/z290048663/article/details/128950092?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22128950092%22%2C%22source%22%3A%22z290048663%22%7D" target="_blank" rel="noopener nofollow ugc">CUDA:Out Of Memory问题_qq290048663的博客-CSDN博客</a></h3>

  <p>CUDA:Out Of Memor</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>