<h3 dir="auto">System Info</h3>
<p dir="auto">transformers-cli env</p>
<ul dir="auto">
<li><code class="notranslate">transformers</code> version: 4.24.0</li>
<li>Platform: Linux-5.4.0-99-generic-x86_64-with-glibc2.17</li>
<li>Python version: 3.8.12</li>
<li>Huggingface_hub version: 0.10.1</li>
<li>PyTorch version (GPU?): 1.12.1+cu102 (True)</li>
<li>onnxruntime-gpu: 1.13.1</li>
<li>Tensorflow version (GPU?): not installed (NA)</li>
<li>Flax version (CPU?/GPU?/TPU?): not installed (NA)</li>
<li>Jax version: not installed</li>
<li>JaxLib version: not installed</li>
<li>Using GPU in script?: </li>
<li>Using distributed or parallel set-up in script?: </li>
</ul>
<h3 dir="auto">Who can help?</h3>
<p dir="auto">ONNX model conversion: <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/morgan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/morgan">@morgan</a></p>
<h3 dir="auto">Information</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> The official example scripts</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> My own modified scripts</li>
</ul>
<h3 dir="auto">Tasks</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> An officially supported task in the <code class="notranslate">examples</code> folder (such as GLUE/SQuAD, ...)</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> My own task or dataset (give details below)</li>
</ul>
<h3 dir="auto">Reproduction</h3>
<p dir="auto">This command line:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="python -m transformers.onnx --model pszemraj/long-t5-tglobal-base-16384-book-summary --feature seq2seq-lm-with-past --preprocessor tokenizer --framework pt ."><pre class="notranslate"><code class="notranslate">python -m transformers.onnx --model pszemraj/long-t5-tglobal-base-16384-book-summary --feature seq2seq-lm-with-past --preprocessor tokenizer --framework pt .
</code></pre></div>
<p dir="auto">Gives me the following error during export validation:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Validating ONNX model...
Floating point exception (core dumped)"><pre class="notranslate"><code class="notranslate">Validating ONNX model...
Floating point exception (core dumped)
</code></pre></div>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">Having a usable and validated ONNX model.</p>
<h2 dir="auto">Environment info</h2>
<ul dir="auto">
<li><code class="notranslate">transformers</code> version: 4.8.2</li>
<li>Platform: Databricks</li>
<li>Python version: 3.7.10</li>
<li>PyTorch version (GPU?): GPU</li>
<li>Using GPU in script?: No</li>
<li>Using distributed or parallel set-up in script?: Yes</li>
</ul>
<h2 dir="auto">Information</h2>
<p dir="auto">Model I am using : camembert-base:</p>
<p dir="auto">The problem arises when i try to use a tokenizer (from whatever model in my experiments) on multiple thread pools with an Autotokenizer, the error <strong>RuntimeError: Already borrowed</strong> get raised, i haven't tried if the same issues occure whith AutoModel, but i suspect it would, this makes it completly inefficient as it requires to duplicate the tokenizer on each thread (same for model), and is a real problem for packages like Petastorm  /  Horovod.</p>
<h2 dir="auto">To reproduce</h2>
<p dir="auto">Below you'll find a simple snippet of code to reproduce the error:<br>
Steps to reproduce the behavior:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=" from multiprocessing.dummy import Pool as ThreadPool
  
tokenizer =   AutoTokenizer.from_pretrained(pretrained_model_name_or_path=&quot;camembert-base&quot;)
def tokenizer_test(text):
    print(tokenizer(text))
    
pool = ThreadPool(10)  
data_list = ['this is a test'] * 10
pool.map(tokenizer_test, data_list)
pool.close()
pool.join()"><pre class="notranslate"> <span class="pl-k">from</span> <span class="pl-s1">multiprocessing</span>.<span class="pl-s1">dummy</span> <span class="pl-k">import</span> <span class="pl-v">Pool</span> <span class="pl-k">as</span> <span class="pl-v">ThreadPool</span>
  
<span class="pl-s1">tokenizer</span> <span class="pl-c1">=</span>   <span class="pl-v">AutoTokenizer</span>.<span class="pl-en">from_pretrained</span>(<span class="pl-s1">pretrained_model_name_or_path</span><span class="pl-c1">=</span><span class="pl-s">"camembert-base"</span>)
<span class="pl-k">def</span> <span class="pl-en">tokenizer_test</span>(<span class="pl-s1">text</span>):
    <span class="pl-en">print</span>(<span class="pl-en">tokenizer</span>(<span class="pl-s1">text</span>))
    
<span class="pl-s1">pool</span> <span class="pl-c1">=</span> <span class="pl-v">ThreadPool</span>(<span class="pl-c1">10</span>)  
<span class="pl-s1">data_list</span> <span class="pl-c1">=</span> [<span class="pl-s">'this is a test'</span>] <span class="pl-c1">*</span> <span class="pl-c1">10</span>
<span class="pl-s1">pool</span>.<span class="pl-en">map</span>(<span class="pl-s1">tokenizer_test</span>, <span class="pl-s1">data_list</span>)
<span class="pl-s1">pool</span>.<span class="pl-en">close</span>()
<span class="pl-s1">pool</span>.<span class="pl-en">join</span>()</pre></div>
<p dir="auto">However this works fine if i switch the Autotokenizer with CamembertTokenizer.from_pretrained("camembert-base") for example.</p>