Fixed datatype related issues in DataCollatorForLanguageModeling
#36457
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes two issues regarding the test
tests/trainer/test_data_collator.py::TFDataCollatorIntegrationTest::test_all_mask_replacement
:RuntimeError: "bernoulli_tensor_cpu_p_" not implemented for 'Long'
. This is because themask_replacement_prob=1
andtorch.bernoulli
doesn't accept this type (which would be atorch.long
dtype instead). I fixed this by manually casting the probability arguments in the__post_init__
function ofDataCollatorForLanguageModeling
.tensorflow.python.framework.errors_impl.InvalidArgumentError: cannot compute Equal as input #1(zero-based) was expected to be a int64 tensor but is a int32 tensor [Op:Equal]
due to the line
tf.reduce_all((batch["input_ids"] == inputs) | (batch["input_ids"] == tokenizer.mask_token_id))
in
test_data_collator.py
. This occurs because the type of theinputs
variable istf.int32
. Solved this by manually casting it totf.int64
in the test, as the expected return type ofbatch["input_ids"]
istf.int64
.These changes were done on Python
3.12.8
. The dependencies installed were aspip install -e ".[dev]"
along with:Motivation: I wanted to make some contributions to
DataCollatorForLanguageModeling
, unfortunately though the tests were failing on the existing code itself. I thought I'll fix these bugs before moving forward with that.Fixes # (issue)
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@Rocketknight1 should be able to review this!