mixin.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from abc import abstractmethod
  15. class BatchSizeMixin:
  16. NAME = "ReadCmp"
  17. def __init__(self, batch_size=1):
  18. self._batch_size = batch_size
  19. @property
  20. def batch_size(self):
  21. return self._batch_size
  22. @batch_size.setter
  23. def batch_size(self, value):
  24. if value <= 0:
  25. raise ValueError("Batch size must be positive.")
  26. self._batch_size = value
  27. class PPEngineMixin:
  28. NAME = "PPEngineCmp"
  29. def __init__(self, option=None):
  30. self._option = option
  31. @property
  32. def option(self):
  33. return self._option
  34. @option.setter
  35. def option(self, value):
  36. if value is not None and value != self.option:
  37. self._option = value
  38. self._reset()
  39. @abstractmethod
  40. def _reset(self):
  41. raise NotImplementedError