コード例 #1
0
    def __init__(self, samples_per_insert: float, min_size_to_sample: int,
                 error_buffer: Union[float, Tuple[float, float]]):
        """Constructor of SampleToInsertRatio.

    Args:
      samples_per_insert: The average number of times the learner should sample
        each item in the replay error_buffer during the item's entire lifetime.
      min_size_to_sample: The minimum number of items that the table must
        contain  before transitioning into stage 2.
      error_buffer: Maximum size of the "error" before calls should be blocked.
        When a single value is provided then inferred range is
          (
            min_size_to_sample * samples_per_insert - error_buffer,
            min_size_to_sample * samples_per_insert + error_buffer
          )
        The offset is added so that the error tracked is for the insert/sample
        ratio only takes into account operatons occurring AFTER stage 1. If a
        range (two float tuple) then the values are used without any offset.

    Raises:
      ValueError: If error_buffer is smaller than max(1.0, samples_per_inserts).
    """
        if isinstance(error_buffer, float) or isinstance(error_buffer, int):
            offset = samples_per_insert * min_size_to_sample
            min_diff = offset - error_buffer
            max_diff = offset + error_buffer
        else:
            min_diff, max_diff = error_buffer

        if max_diff - min_diff < 2 * max(1.0, samples_per_insert):
            raise ValueError(
                'The size of error_buffer must be >= 2 * max(1.0, samples_per_insert) '
                'as smaller values could completely block samples and/or insert calls.'
            )

        if max_diff < samples_per_insert * min_size_to_sample:
            logging.warning(
                'The range covered by error_buffer is below '
                'samples_per_insert * min_size_to_sample. If the sampler cannot '
                'sample concurrently, this will result in a deadlock as soon as '
                'min_size_to_sample items have been inserted.')
        if min_diff > samples_per_insert * min_size_to_sample:
            raise ValueError(
                'The range covered by error_buffer is above '
                'samples_per_insert * min_size_to_sample. This will result in a '
                'deadlock as soon as min_size_to_sample items have been inserted.'
            )

        if min_size_to_sample < 1:
            raise ValueError(
                f'min_size_to_sample ({min_size_to_sample}) must be a positive '
                f'integer')

        super().__init__(
            pybind.RateLimiter(samples_per_insert=samples_per_insert,
                               min_size_to_sample=min_size_to_sample,
                               min_diff=min_diff,
                               max_diff=max_diff))
コード例 #2
0
    def __init__(self, size: int):
        """Constructor of Stack (do not use directly).

    Args:
      size: Maximum size of the stack.
    """
        super().__init__(
            pybind.RateLimiter(samples_per_insert=1.0,
                               min_size_to_sample=1,
                               min_diff=0.0,
                               max_diff=size))
コード例 #3
0
    def __init__(self, min_size_to_sample: int):
        if min_size_to_sample < 1:
            raise ValueError(
                f'min_size_to_sample ({min_size_to_sample}) must be a positive '
                f'integer')

        super().__init__(
            pybind.RateLimiter(samples_per_insert=1.0,
                               min_size_to_sample=min_size_to_sample,
                               min_diff=-sys.float_info.max,
                               max_diff=sys.float_info.max))
コード例 #4
0
ファイル: rate_limiters.py プロジェクト: deepmind/reverb
 def __init__(self, samples_per_insert: float, min_size_to_sample: int,
              min_diff: float, max_diff: float):
     self._samples_per_insert = samples_per_insert
     self._min_size_to_sample = min_size_to_sample
     self._min_diff = min_diff
     self._max_diff = max_diff
     self.internal_limiter = pybind.RateLimiter(
         samples_per_insert=samples_per_insert,
         min_size_to_sample=min_size_to_sample,
         min_diff=min_diff,
         max_diff=max_diff)