python/라이브러리

[Tensorflow] InternalError: Blas xGEMM launch failed : a.shape=[1,15,1024], b.shape=[1,1024,1024], m=15, n=1024, k=1024 [Op:MatMul] 오류

sillon 2023. 1. 25. 21:54
728x90
반응형

InternalError                             Traceback (most recent call last)
Cell In[19], line 3
      1 # 신규
      2 with strategy.scope():
----> 3   model = TFBertForQuestionAnswering("bert-large-uncased-whole-word-masking-finetuned-squad")
      4   optimizer = tf.keras.optimizers.Adam(learning_rate=5e-5)
      5   loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False)

Cell In[18], line 4, in TFBertForQuestionAnswering.__init__(self, model_name)
      2 def __init__(self, model_name):
      3     super(TFBertForQuestionAnswering, self).__init__()
----> 4     self.bert = TFBertModel.from_pretrained(model_name, from_pt=True)
      5     self.qa_outputs = tf.keras.layers.Dense(2,
      6                                             kernel_initializer=tf.keras.initializers.TruncatedNormal(0.02),
      7                                             name='qa_outputs')
      8     self.softmax = tf.keras.layers.Activation(tf.keras.activations.softmax)

File ~/anaconda3/envs/py39/lib/python3.9/site-packages/transformers/modeling_tf_utils.py:1290, in TFPreTrainedModel.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
   1287     from .modeling_tf_pytorch_utils import load_pytorch_checkpoint_in_tf2_model
   1289     # Load from a PyTorch checkpoint
-> 1290     return load_pytorch_checkpoint_in_tf2_model(model, resolved_archive_file, allow_missing_keys=True)
   1292 # we might need to extend the variable scope for composite models
   1293 if load_weight_prefix is not None:
...
-> 6897 six.raise_from(core._status_to_exception(e.code, message), None)

File <string>:3, in raise_from(value, from_value)

InternalError: Blas xGEMM launch failed : a.shape=[1,15,1024], b.shape=[1,1024,1024], m=15, n=1024, k=1024 [Op:MatMul]

주피터 노트북에서 한 파일에 모델 학습을 하면서 다른 파일의 모델도 학습하려니 해당 오류가 떴다.

 

오류가 뜬 이유

[참고] https://stackoverflow.com/questions/37337728/tensorflow-internalerror-blas-sgemm-launch-failed

 

[원인] GPU Memory를 TensorFlow process가 독점하고 있는데, 다른 TensorFlow Process가 GPU Memory에 접근하려고 할때 발생하는 에러.

 

[해결책] TensorFlow Session 설정에서 GPU 메모리를 공유하도록 설정해도 되겠지만, 일단 가장 간단한 방법은 jupyter notebook 을 종료하고, 다시 실행시켜서 하나의 kernel만 실행시킨다. jupyter notebook 을 실행시킨 상태에서 pycharm 에서 실행시킨다면 위와 같은 에러가 발생한다.

 

728x90
반응형