Ошибка CUDA: сработало утверждение на стороне устройства. Скомпилируйте с помощью `TORCH_USE_CUDA_DSA`, чтобы включить уPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Ошибка CUDA: сработало утверждение на стороне устройства. Скомпилируйте с помощью `TORCH_USE_CUDA_DSA`, чтобы включить у

Сообщение Anonymous »

Я встретил эту ошибку в функции потерь. Пример ниже:
Мой код работал нормально, но что-то потерялось, не могу найти проблему. Пробовал обновлять библиотеки, тестировать предыдущие версии, проверял тензоры, индексы... Кто-нибудь может мне помочь, в конце страницы есть ссылка на мой репозиторий с файлами, которые я использовал.
Версия библиотеки:

Код: Выделить всё

Windows 11
GTX 1050 TI (Driver-Version==552.12)
Python==3.12.3
transformers==4.39.3
tokenizers==0.15.2
torch==2.2.2+cu121
datasets==2.18.0
Cudatoolkit==12.1
CuDNN==8801

transformers-cli env:
- `transformers` version: 4.39.3
- Platform: Windows-11-10.0.22631-SP0
- Python version: 3.12.3
- Huggingface_hub version: 0.22.2
- Safetensors version: 0.4.3
- Accelerate version: 0.29.2
- Accelerate config:    not found
- PyTorch version (GPU?): 2.2.2+cu121 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: 
- Using distributed or parallel set-up in script?: 
Объем словарного запаса: Размер входного идентификатора:

Код: Выделить всё

Minimum ID: 0, Maximum ID: 5007
Пример вывода input_ids:

Код: Выделить всё

input_ids:  [[0, 304, 860, 1026, 261, 326, 1578, 16, 4891, 16, 507, 4109, 16, 300, 463, 285, 783, 1887, 432, 960, 16, 285, 2016, 315, 3550, 374, 325, 1819, 16, 924, 4846, 971, 1782, 18, 374, 1183, 3494, 16, 833, 575, 1083, 324, 285, 300, 463, 916, 1908, 2802, 358, 1209, 285, 262, 1026, 18, 276, 718, 354, 1952, 306, 276, 773, 358, 3488, 18, 367, 276, 1092, 285, 1020, 288, 1369, 464, 2414, 276, 2158, 271, 422, 312, 2926, 91, 87, 79, 93, 414, 276, 1891, 1647, 16, 285, 868, 4067, 271, 2379, 16, 271, 853, 288, 464, 753, 262, 1755, 263, 285, 288, 478, 956, 422, 3227, 265, 358, 4498, 271, 1005, 454, 16, 358, 646, 285, 262, 4539, 271, 264, 2955, 3879, 80, 18, 590, 463, 1503, 16, 285, 1186, 641, 271, 4372, 367, 989, 1111, 742, 1576, 637, 3559, 352, 334, 959, 16, 1417, 89, 594, 709, 600, 334, 439, 385, 3991, 315, 395, 70, 287, 402, 263, 1191, 1519, 1680, 16, 367, 334, 1042, 322, 575, 2165, 16, 957, 364, 1026, 16, 981, 874, 4127, 339, 4426, 594, 1766, 315, 285, 2286, 377, 18, 1168, 504, 17, 1534, 315, 1120, 3915, 285, 1077, 364, 4163, 4522, 366, 16, 315, 3915, 358, 1178, 263, 358, 2665, 931, 18, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 2921, 818, 712, 764, 276, 737, 325, 1782, 31, 1521, 295, 764, 4648, 285, 338, 339, 641, 798, 322, 2156, 262, 4559, 2445, 16, 285, 2145, 285, 322, 491, 2109, 579, 325, 662, 389, 271, 4013, 3642, 579, 4195, 624, 350, 280, 414, 276, 921, 315, 1939, 16, 325, 330, 333, 2907, 16, 285, 1507, 285, 322, 306, 1994, 289, 352, 300, 1392, 16, 607, 950, 352, 1543, 287, 2484, 1294, 16, 2405, 16, 4847, 18, 3008, 291, 4648, 16, 334, 1922, 263, 334, 1483, 491, 3094, 3210, 338, 339, 2325, 3291, 69, 31, 367, 1302, 16, 640, 359, 586, 3492, 304, 339, 935, 2997, 358, 4680, 285, 367, 334, 285, 2239, 304, 432, 2325, 325, 556, 18, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
Код:

Код: Выделить всё

import os
import traceback
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
os.environ['CUDA_LAUNCH_BLOCKING'] = "1"
os.environ['TORCH_USE_CUDA_DSA'] = '1'
import torch
from tokenizers.implementations import ByteLevelBPETokenizer
from tokenizers.processors import BertProcessing
from transformers import RobertaConfig
from transformers import RobertaForMaskedLM
from transformers import RobertaTokenizerFast
from transformers import DataCollatorForLanguageModeling
from transformers import Trainer, TrainingArguments
from transformers import pipeline
from datasets import load_dataset

def read_document(document_path):
with open(document_path, 'r', encoding='utf-8') as file:
return file.read()

def main():
try:
# Create the directory if it does not exist
if not os.path.exists('raw_model'):
os.makedirs('raw_model')

training_data = 'C:\\Users\\caiqu\\OneDrive\\Documentos\\IA\\crepusculoDosIdolos.txt'

os.path.join(os.path.abspath('.'),  'raw_model')

# Initialize a ByteLevelBPETokenizer
tokenizer = ByteLevelBPETokenizer()
tokenizer.train(files=[training_data], vocab_size=52_000, min_frequency=2, special_tokens=[
"",
"
",
"",
"",
"",
])

tokenizer.save_model('raw_model')

tokenizer = RobertaTokenizerFast.from_pretrained('raw_model', max_len=512)

print("Vocabulary size: ", tokenizer.vocab_size)

tokenizer._tokenizer.post_process = BertProcessing(
("", tokenizer.convert_tokens_to_ids("")),
("", tokenizer.convert_tokens_to_ids("")),
)

# Creating our Transformer
config = RobertaConfig(
vocab_size=52_000,
max_position_embeddings=512,
num_attention_heads=12,
num_hidden_layers=6,
type_vocab_size=1,
)

model = RobertaForMaskedLM(config=config)
model.num_parameters()

# Check if a GPU is available and, if not, use the CPU
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

# Move the model to the device
model = model.to(device)
print("Model is using : ", next(model.parameters()).device)

# Loading the dataset
dataset = load_dataset('text', data_files=training_data)

# Tokenizing the dataset
def tokenize_function(examples):
encodings = tokenizer(examples["text"], truncation=True, padding='max_length', max_length=512)

# Opening the file in write mode
with open('indices.txt', 'w') as f:
# Writing the indices to the file
f.write("input_ids: "  + str(encodings['input_ids']) + "\n")

return {"input_ids": encodings['input_ids']}

tokenized_datasets = dataset.map(tokenize_function, batched=True, num_proc=8, remove_columns=["text"])

with open('results.txt', 'w') as f:
for batch in tokenized_datasets['train']:
input_ids = torch.tensor(batch['input_ids']).to(device)  # Add .to(device) here
print("Inputs are using :", input_ids.device)  # Now should print 'cuda' if a GPU is available
min_id = input_ids.min().item()
max_id = input_ids.max().item()
f.write(f'Minimum ID: {min_id}, Maximum ID: {max_id}\n')

data_collator = DataCollatorForLanguageModeling(
tokenizer=tokenizer, mlm=True, mlm_probability=0.1
)

output_dir = os.path.abspath('C:\\Users\\caiqu\\OneDrive\\Documentos\\IA\\raw_model')

training_args = TrainingArguments(
output_dir=output_dir,
overwrite_output_dir=True,
num_train_epochs=1200,
per_device_train_batch_size=64,
save_steps=10_000,
save_total_limit=2,
prediction_loss_only=True,
)

trainer = Trainer(
model=model,
args=training_args,
data_collator=data_collator,
train_dataset=tokenized_datasets['train'],
)

# Check if the output directory exists before starting the training
if not os.path.exists(output_dir):
os.makedirs(output_dir)

# Enable mixed precision
trainer.train()

trainer.save_model('raw_model')

# Create a fill-mask pipeline with the model and the tokenizer
fill_mask = pipeline(
"fill-mask",
model='raw_model',
tokenizer='raw_model'
)

while True:  # Infinite loop
question = input("You: ")  # Ask a question to the user
if question.lower() == "exit":  # If the question is "exit"
break  # Exit the loop
response = fill_mask(question)  # Generate a response to the question
print("AI: ", response)  # Print the response

except Exception as e:
with open('error_log.txt', 'w') as f:
f.write(str(e))
f.write(traceback.format_exc())

if __name__ == '__main__':
main()
Ошибка:

Код: Выделить всё

C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\accelerate\accelerator.py:436: FutureWarning: Passing the following arguments to `Accelerator` is deprecated and will be removed in version 1.0 of Accelerate: dict_keys(['dispatch_batches', 'split_batches', 'even_batches', 'use_seedable_sampler']).  Please pass an `accelerate.DataLoaderConfiguration` instead:
dataloader_config = DataLoaderConfiguration(dispatch_batches=None, split_batches=False, even_batches=True, use_seedable_sampler=True)

C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\native\cuda\Indexing.cu:1290: block: [42,0,0], thread: [124,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\native\cuda\Indexing.cu:1290: block: [42,0,0], thread: [125,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\native\cuda\Indexing.cu:1290: block: [42,0,0], thread: [126,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\native\cuda\Indexing.cu:1290: block: [42,0,0], thread: [127,0,0] Assertion `srcIndex <  srcSelectDimSize` failed.
Traceback (most recent call last):
File "c:\Users\caiqu\OneDrive\Documentos\IA\treinar3.py", line 141, in 
main()
File "c:\Users\caiqu\OneDrive\Documentos\IA\treinar3.py", line 122, in main
trainer.train()
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\trainer.py", line 1780, in train
return inner_training_loop(
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\trainer.py", line 2118, in _inner_training_loop
tr_loss_step = self.training_step(model, inputs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\trainer.py", line 3036, in training_step
loss = self.compute_loss(model, inputs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\trainer.py", line 3059, in compute_loss
outputs = model(**inputs)
^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\models\roberta\modeling_roberta.py", line 1084, in forward
outputs = self.roberta(
^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\models\roberta\modeling_roberta.py", line 828, in forward
embedding_output = self.embeddings(
^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\transformers\models\roberta\modeling_roberta.py", line 130, in forward
position_embeddings = self.position_embeddings(position_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\modules\sparse.py", line 163, in forward
return F.embedding(
^^^^^^^^^^^^
File "C:\Users\caiqu\AppData\Local\Programs\Python\Python312\Lib\site-packages\torch\nn\functional.py", line 2237, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: CUDA error: device-side assert triggered
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
Репозитории Github: https://github.com/DonatoReis/bert-new

Подробнее здесь: https://stackoverflow.com/questions/783 ... -dsa-to-en
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»