# Cannot allocate memory in static TLS block

**URL:** <https://discuss.huggingface.co/t/cannot-allocate-memory-in-static-tls-block/20955>\
**Category:** 🤗Transformers\
**Created:** [July 28, 2022, 3:17pm UTC](https://discuss.huggingface.co/t/cannot-allocate-memory-in-static-tls-block/20955 "2022-07-28T15:17:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Indramal](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/indramal/32/61744_2.png) [@Indramal](https://discuss.huggingface.co/u/Indramal)\
**Post date:** [July 28, 2022, 3:17pm UTC](https://discuss.huggingface.co/t/cannot-allocate-memory-in-static-tls-block/20955/1 "2022-07-28T15:17:23Z")

</div>

I am trying to test examples in the website. - [https://huggingface.co/distilbert-base-uncased-distilled-squad](https://huggingface.co/distilbert-base-uncased-distilled-squad)

Fist I tried following code:

```auto
from transformers import pipeline
question_answerer = pipeline("question-answering", model='distilbert-base-uncased-distilled-squad')

context = r"""
Extractive Question Answering is the task of extracting an answer from a text given a question. An example of a
question answering dataset is the SQuAD dataset, which is entirely based on that task. If you would like to fine-tune
a model on a SQuAD task, you may leverage the examples/pytorch/question-answering/run_squad.py script.
"""

result = question_answerer(question="What is a good example of a question answering dataset?", context=context)
print(f"Answer: '{result['answer']}', score: {round(result['score'], 4)}, start: {result['start']}, end: {result['end']}")

```

It shows the following error,

> print(f"Answer: ‘{result[‘answer’]}’, score: {round(result[‘score’], 4)}, start: {result[‘start’]}, end: {result[‘end’]}")  
> TypeError: list indices must be integers or slices, not str

When I try following code,

```auto
from transformers import DistilBertTokenizer, DistilBertModel
import torch
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased-distilled-squad')
model = DistilBertModel.from_pretrained('distilbert-base-uncased-distilled-squad')

question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"

inputs = tokenizer(question, text, return_tensors="pt")
with torch.no_grad():
    outputs = model(**inputs)

print(outputs)

```

It given following error,

> Traceback (most recent call last):  
> File “/usr/local/lib/python3.8/dist-packages/transformers/utils/import\_utils.py”, line 1002, in \_get\_module  
> return importlib.import\_module(“.” + module\_name, self. **name** )  
> File “/usr/lib/python3.8/importlib/ **init**.py”, line 127, in import\_module  
> return \_bootstrap.\_gcd\_import(name[level:], package, level)  
> File “”, line 1014, in \_gcd\_import  
> File “”, line 991, in \_find\_and\_load  
> File “”, line 961, in \_find\_and\_load\_unlocked  
> File “”, line 219, in \_call\_with\_frames\_removed  
> File “”, line 1014, in \_gcd\_import  
> File “”, line 991, in \_find\_and\_load  
> File “”, line 975, in \_find\_and\_load\_unlocked  
> File “”, line 671, in \_load\_unlocked  
> File “”, line 848, in exec\_module  
> File “”, line 219, in \_call\_with\_frames\_removed  
> File “/usr/local/lib/python3.8/dist-packages/transformers/data/ **init**.py”, line 30, in   
> from .metrics import glue\_compute\_metrics, xnli\_compute\_metrics  
> File “/usr/local/lib/python3.8/dist-packages/transformers/data/metrics/ **init**.py”, line 22, in   
> if is\_sklearn\_available():  
> File “/usr/local/lib/python3.8/dist-packages/transformers/utils/import\_utils.py”, line 492, in is\_sklearn\_available  
> return is\_scipy\_available() and importlib.util.find\_spec(“sklearn.metrics”)  
> File “/usr/lib/python3.8/importlib/util.py”, line 94, in find\_spec  
> parent = **import** (parent\_name, fromlist=[‘ **path** ’])  
> File “/usr/local/lib/python3.8/dist-packages/sklearn/ **init**.py”, line 83, in   
> from .utils.\_show\_versions import show\_versions  
> File “/usr/local/lib/python3.8/dist-packages/sklearn/utils/\_show\_versions.py”, line 14, in   
> from .\_openmp\_helpers import \_openmp\_parallelism\_enabled  
> ImportError: /lib/aarch64-linux-gnu/libgomp.so.1: cannot allocate memory in static TLS block
> 
> The above exception was the direct cause of the following exception:
> 
> Traceback (most recent call last):  
> File “/usr/local/lib/python3.8/dist-packages/transformers/utils/import\_utils.py”, line 1002, in \_get\_module  
> return importlib.import\_module(“.” + module\_name, self. **name** )  
> File “/usr/lib/python3.8/importlib/ **init**.py”, line 127, in import\_module  
> return \_bootstrap.\_gcd\_import(name[level:], package, level)  
> File “”, line 1014, in \_gcd\_import  
> File “”, line 991, in \_find\_and\_load  
> File “”, line 975, in \_find\_and\_load\_unlocked  
> File “”, line 671, in \_load\_unlocked  
> File “”, line 848, in exec\_module  
> File “”, line 219, in \_call\_with\_frames\_removed  
> File “/usr/local/lib/python3.8/dist-packages/transformers/models/distilbert/modeling\_tf\_distilbert.py”, line 34, in   
> from …modeling\_tf\_utils import (  
> File “/usr/local/lib/python3.8/dist-packages/transformers/modeling\_tf\_utils.py”, line 42, in   
> from . import DataCollatorWithPadding, DefaultDataCollator  
> File “”, line 1039, in \_handle\_fromlist  
> File “/usr/local/lib/python3.8/dist-packages/transformers/utils/import\_utils.py”, line 992, in **getattr**  
> module = self.\_get\_module(self.\_class\_to\_module[name])  
> File “/usr/local/lib/python3.8/dist-packages/transformers/utils/import\_utils.py”, line 1004, in \_get\_module  
> raise RuntimeError(  
> RuntimeError: Failed to import transformers.data.data\_collator because of the following error (look up to see its traceback):  
> /lib/aarch64-linux-gnu/libgomp.so.1: cannot allocate memory in static TLS block
> 
> The above exception was the direct cause of the following exception:
> 
> Traceback (most recent call last):  
> File “/home/user/Desktop/nlp2.py”, line 1, in   
> from transformers import DistilBertTokenizer, TFDistilBertForQuestionAnswering  
> File “”, line 1039, in \_handle\_fromlist  
> File “/usr/local/lib/python3.8/dist-packages/transformers/utils/import\_utils.py”, line 993, in **getattr**  
> value = getattr(module, name)  
> File “/usr/local/lib/python3.8/dist-packages/transformers/utils/import\_utils.py”, line 992, in **getattr**  
> module = self.\_get\_module(self.\_class\_to\_module[name])  
> File “/usr/local/lib/python3.8/dist-packages/transformers/utils/import\_utils.py”, line 1004, in \_get\_module  
> raise RuntimeError(  
> RuntimeError: Failed to import transformers.models.distilbert.modeling\_tf\_distilbert because of the following error (look up to see its traceback):  
> Failed to import transformers.data.data\_collator because of the following error (look up to see its traceback):  
> /lib/aarch64-linux-gnu/libgomp.so.1: cannot allocate memory in static TLS block

The I tried following code:

```auto
from transformers import DistilBertTokenizer, TFDistilBertForQuestionAnswering
import tensorflow as tf

tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-distilled-squad")
model = TFDistilBertForQuestionAnswering.from_pretrained("distilbert-base-uncased-distilled-squad")

question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"

inputs = tokenizer(question, text, return_tensors="tf")
outputs = model(**inputs)

answer_start_index = int(tf.math.argmax(outputs.start_logits, axis=-1)[0])
answer_end_index = int(tf.math.argmax(outputs.end_logits, axis=-1)[0])

predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
tokenizer.decode(predict_answer_tokens)

```

That given following error

> Some weights of the model checkpoint at distilbert-base-uncased-distilled-squad were not used when initializing DistilBertModel: [‘qa\_outputs.weight’, ‘qa\_outputs.bias’]
> 
> - This IS expected if you are initializing DistilBertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
> - This IS NOT expected if you are initializing DistilBertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).  
> BaseModelOutput(last\_hidden\_state=tensor([[[nan, nan, nan, …, nan, nan, nan],  
> [nan, nan, nan, …, nan, nan, nan],  
> [nan, nan, nan, …, nan, nan, nan],  
> …,  
> [nan, nan, nan, …, nan, nan, nan],  
> [nan, nan, nan, …, nan, nan, nan],  
> [nan, nan, nan, …, nan, nan, nan]]]), hidden\_states=None, attentions=None)

I think all error are relatted to memory allocate. How can i solve this issue?
