Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: The input size 0, plus negative padding 0 and 0 resulted in a negative output size, which is invalid. Check dimension 1 of your input. #188

Open
KameniAlexNea opened this issue Sep 6, 2024 · 1 comment

Comments

@KameniAlexNea
Copy link

KameniAlexNea commented Sep 6, 2024

Hello folks,

I am trying to fine-tune GliNER on custom dataset (LMR/LMD) and after some steps, I encountered this issue :

File "~/gliner_finetuing.py", line 79, in <module>
    main()
  File "~/gliner_finetuing.py", line 75, in main
    trainer.train()
  File "~/.venv/lib/python3.9/site-packages/transformers/trainer.py", line 1938, in train
    return inner_training_loop(
  File "~/.venv/lib/python3.9/site-packages/transformers/trainer.py", line 2236, in _inner_training_loop
    for step, inputs in enumerate(epoch_iterator):
  File "~/.venv/lib/python3.9/site-packages/accelerate/data_loader.py", line 568, in __iter__
    next_batch = next(dataloader_iter)
  File "~/.venv/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 630, in __next__
    data = self._next_data()
  File "~/.venv/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 673, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File "~/.venv/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py", line 55, in fetch
    return self.collate_fn(data)
  File "~/.venv/lib/python3.9/site-packages/gliner/data_processing/collator.py", line 31, in __call__
    model_input = self.data_processor.collate_fn(raw_batch, prepare_labels=self.prepare_labels)
  File "~/.venv/lib/python3.9/site-packages/gliner/data_processing/processor.py", line 203, in collate_fn
    model_input_batch = self.tokenize_and_prepare_labels(batch, prepare_labels, *args, **kwargs)
  File "~/.venv/lib/python3.9/site-packages/gliner/data_processing/processor.py", line 335, in tokenize_and_prepare_labels
    labels = self.create_labels(batch)
  File "~/.venv/lib/python3.9/site-packages/gliner/data_processing/processor.py", line 326, in create_labels
    labels_batch = pad_2d_tensor(labels_batch)
  File "~/.venv/lib/python3.9/site-packages/gliner/data_processing/utils.py", line 25, in pad_2d_tensor
    padded_tensor = torch.nn.functional.pad(tensor, (0, col_padding, 0, row_padding),
  File "~/.venv/lib/python3.9/site-packages/torch/nn/functional.py", line 4552, in pad
    return torch._C._nn.pad(input, pad, mode, value)
RuntimeError: The input size 0, plus negative padding 0 and 0 resulted in a negative output size, which is invalid. Check dimension 1 of your input.

Note that this issue occurred after around 2 epochs, it shouldn't be related to the data.

@KameniAlexNea
Copy link
Author

This comment solved the issue:

#139 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant