Skip to content

Add manual eviction support - #3

Merged
YassineYousfi merged 4 commits into
masterfrom
add-reinsert-prob
Jun 19, 2026
Merged

Add manual eviction support#3
YassineYousfi merged 4 commits into
masterfrom
add-reinsert-prob

Conversation

@tfpgh

@tfpgh tfpgh commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Adds config.reinsert_prob to have some probability of reinserting a sample into the buffer after being read. Set to 0.0 by default so it shouldn't affect existing code.

This could be made to work with fill_once but it's a lot uglier and I don't think anyone would use it.

@tfpgh
tfpgh requested a review from haraschax June 17, 2026 17:13
@haraschax
haraschax requested review from YassineYousfi and Copilot and removed request for haraschax June 17, 2026 18:11

This comment was marked as spam.

Comment thread gigashuffle/multiprocess.py Outdated
if reinsert:
r.sadd(f'{queue_name}-full', *reinsert)
if free:
r.sadd(f'{queue_name}-empty', *free)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idx_list is already random,
something like this should be enough

-     r.sadd(f'{queue_name}-empty', *idx_list)
+
+     keep = int(config.reinsert_prob * len(idx_list))
+     r.sadd(f'{queue_name}-empty', *idx_list[keep:])
+     if keep > 0: r.sadd('{queue_name}-full', *idx_list[:keep])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The randomness in idx_list comes from Redis SPOP. This guarantees the set of elements is random but the order they're returned in is often not random:
$ redis-cli
127.0.0.1:6379> SADD spop_test 1 2 3 4 5 6 7 8 9 10 11 12
(integer) 12
127.0.0.1:6379> SPOP spop_test 4
1) "7"
2) "8"
3) "9"
4) "11"
127.0.0.1:6379> SPOP spop_test 4
1) "3"
2) "6"
3) "10"
4) "12"
  1. This makes the number of elements reinserted constant instead of a binomial distribution, not sure if this distinction matters.

@tfpgh

tfpgh commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@YassineYousfi I looked at tianshou, RLlib, and stable-baselines3 and you're generally right: replay happens on the training side and not in the dataloader.

I do still think putting reinsertion in gigashuffle is cleaner. The way we want to use it in rldriving is not specific to RL, it's a generic "reuse expensive samples" parameter. gigashuffle already introduces off-policy-ness with its buffer. Putting replay in training would stack another buffer which is harder to reason about in my opinion. It also bloats training code a lot more than it adds here.

@haraschax

Copy link
Copy Markdown

I agree it's cleaner in gigashuffle

@YassineYousfi

Copy link
Copy Markdown
Collaborator

I think the better way to do this is:

  • add an option to not evict on reads DataloaderConfig
  • make the dataloader return the indices in the Buffer objects
  • expose an eviction method in MultiprocessShuffledDataloader

@haraschax

Copy link
Copy Markdown

Agreed, that leaves it to the trainer to choose an eviction strategy

@tfpgh
tfpgh force-pushed the add-reinsert-prob branch from 3f3d7d7 to 0c74ae9 Compare June 18, 2026 01:39
Comment thread gigashuffle/multiprocess.py Outdated
pass

def __iter__(self) -> Iterator[Buffer]:
def __iter__(self) -> Iterator[Buffer | tuple[Buffer, list[int]]]:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the interface, ty in xx will complain on existing code

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's reasonable to have Buffer always contain the indices.

This comment was marked as spam.

@YassineYousfi

Copy link
Copy Markdown
Collaborator

lgtm besides always returning the indices (maybe as an attribute of the Buffer objects if that’s clean)

@tfpgh

tfpgh commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

lgtm besides always returning the indices (maybe as an attribute of the Buffer objects if that’s clean)

I agree, this is cleaner and existing code shouldn't be affected (unless it iterates over the dictionary keys in some weird way).

@tfpgh
tfpgh requested a review from YassineYousfi June 18, 2026 22:00
@tfpgh tfpgh changed the title Add reinsert prob Add manual eviction support Jun 18, 2026
@YassineYousfi
YassineYousfi merged commit d0c35b7 into master Jun 19, 2026
1 check passed
@tfpgh
tfpgh deleted the add-reinsert-prob branch June 19, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants