For models that inherit from [`PreTrainedModel`], uses that method to compute the number of floating point operations for every backward + forward pass. If using another model, either implement such a method in the model or subclass and override this method. Args:
(self, inputs: dict[str, torch.Tensor | Any])
| 3907 | self.current_flos = 0 |
| 3908 | |
| 3909 | def floating_point_ops(self, inputs: dict[str, torch.Tensor | Any]) -> int: |
| 3910 | """ |
| 3911 | For models that inherit from [`PreTrainedModel`], uses that method to compute the number of floating point |
| 3912 | operations for every backward + forward pass. If using another model, either implement such a method in the |
| 3913 | model or subclass and override this method. |
| 3914 | |
| 3915 | Args: |
| 3916 | inputs (`dict[str, torch.Tensor | Any]`): |
| 3917 | The inputs and targets of the model. |
| 3918 | |
| 3919 | Returns: |
| 3920 | `int`: The number of floating-point operations. |
| 3921 | """ |
| 3922 | if (main_input := getattr(self.model, "main_input_name", "input_ids")) in inputs and hasattr( |
| 3923 | self.model, "num_parameters" |
| 3924 | ): |
| 3925 | return 6 * inputs[main_input].numel() * self.model.num_parameters(exclude_embeddings=True) |
| 3926 | return 0 |
| 3927 | |
| 3928 | # ---- Hub Integration ---- |
| 3929 |
no test coverage detected