Fixing tests for perceiver (texts) (#14719)
* Fixing tests for perceiver (texts) * For MaskedLM
This commit is contained in:
@@ -915,6 +915,7 @@ class PerceiverForMaskedLM(PerceiverPreTrainedModel):
|
||||
output_hidden_states=None,
|
||||
labels=None,
|
||||
return_dict=None,
|
||||
input_ids=None,
|
||||
):
|
||||
r"""
|
||||
labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size, sequence_length)`, `optional`):
|
||||
@@ -922,6 +923,10 @@ class PerceiverForMaskedLM(PerceiverPreTrainedModel):
|
||||
config.vocab_size]`` (see ``input_ids`` docstring) Tokens with indices set to ``-100`` are ignored
|
||||
(masked), the loss is only computed for the tokens with labels in ``[0, ..., config.vocab_size]``
|
||||
"""
|
||||
if inputs is not None and input_ids is not None:
|
||||
raise ValueError("You cannot use both `inputs` and `input_ids`")
|
||||
elif inputs is None and input_ids is not None:
|
||||
inputs = input_ids
|
||||
|
||||
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
||||
|
||||
@@ -994,6 +999,7 @@ class PerceiverForSequenceClassification(PerceiverPreTrainedModel):
|
||||
output_hidden_states=None,
|
||||
labels=None,
|
||||
return_dict=None,
|
||||
input_ids=None,
|
||||
):
|
||||
r"""
|
||||
labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size,)`, `optional`):
|
||||
@@ -1015,6 +1021,10 @@ class PerceiverForSequenceClassification(PerceiverPreTrainedModel):
|
||||
>>> outputs = model(inputs=inputs)
|
||||
>>> logits = outputs.logits
|
||||
"""
|
||||
if inputs is not None and input_ids is not None:
|
||||
raise ValueError("You cannot use both `inputs` and `input_ids`")
|
||||
elif inputs is None and input_ids is not None:
|
||||
inputs = input_ids
|
||||
|
||||
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
||||
|
||||
@@ -1121,6 +1131,7 @@ class PerceiverForImageClassificationLearned(PerceiverPreTrainedModel):
|
||||
output_hidden_states=None,
|
||||
labels=None,
|
||||
return_dict=None,
|
||||
pixel_values=None,
|
||||
):
|
||||
r"""
|
||||
labels (:obj:`torch.LongTensor` of shape :obj:`(batch_size,)`, `optional`):
|
||||
@@ -1149,6 +1160,11 @@ class PerceiverForImageClassificationLearned(PerceiverPreTrainedModel):
|
||||
>>> predicted_class_idx = logits.argmax(-1).item()
|
||||
>>> print("Predicted class:", model.config.id2label[predicted_class_idx])
|
||||
"""
|
||||
if inputs is not None and pixel_values is not None:
|
||||
raise ValueError("You cannot use both `inputs` and `pixel_values`")
|
||||
elif inputs is None and pixel_values is not None:
|
||||
inputs = pixel_values
|
||||
|
||||
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
||||
|
||||
outputs = self.perceiver(
|
||||
|
||||
@@ -196,6 +196,13 @@ class PerceiverModelTester:
|
||||
num_labels=self.num_labels,
|
||||
)
|
||||
|
||||
def get_pipeline_config(self):
|
||||
config = self.get_config()
|
||||
# Byte level vocab
|
||||
config.vocab_size = 261
|
||||
config.max_position_embeddings = 40
|
||||
return config
|
||||
|
||||
def create_and_check_for_masked_lm(self, config, inputs, input_mask, sequence_labels, token_labels):
|
||||
model = PerceiverForMaskedLM(config=config)
|
||||
model.to(torch_device)
|
||||
|
||||
Reference in New Issue
Block a user