mixin.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. class BatchSizeMixin:
  15. NAME = "ReadCmp"
  16. def __init__(self, batch_size=1):
  17. self._batch_size = batch_size
  18. @property
  19. def batch_size(self):
  20. return self._batch_size
  21. @batch_size.setter
  22. def batch_size(self, value):
  23. if value <= 0:
  24. raise ValueError("Batch size must be positive.")
  25. self._batch_size = value
  26. class PPEngineMixin:
  27. NAME = "PPEngineCmp"
  28. def __init__(self, option=None):
  29. self._option = option
  30. @property
  31. def option(self):
  32. return self._option
  33. @option.setter
  34. def option(self, value):
  35. if value != self.option:
  36. self._option = value
  37. self._reset()