GFNOrg / torchgfn

GFlowNet library
https://torchgfn.readthedocs.io/en/latest/
Other
209 stars 26 forks source link

Prioritized replay buffer #175

Closed josephdviviano closed 5 months ago

josephdviviano commented 5 months ago

I've adde a prioritized replay buffer. This:

In general, uniqueness is defined as distances between the candidate batch and buffer states using a p_norm -- this is configurable by the user. The default settings use a p-norm of 1 and a distance threshold of 0, i.e., the added states should not be identical to any state already in the buffer.

Important you can test this using

tutorials/examples/train_hypergrid.py --replay_buffer_size 1000 --replay_buffer_prioritized

Note: currently, the standard buffer outperforms the prioritized buffer using these default settings!

In the debugger, I could determine that no samples were ever added to the buffer after it was originally filled, because the states were not found to be unique. I.e., in replay_buffer.py the following logic always had idx_batch_buffer as completely full of False:

    # Remove non-diverse examples according to the above distances.
    idx_batch_batch = batch_batch_dist > self.cutoff_distance
    idx_batch_buffer = batch_buffer_dist > self.cutoff_distance
    idx_diverse = idx_batch_batch & idx_batch_buffer

@saleml I'd be curious to get your opinion on this. Perhaps we can tweak the implementation of the prioritized replay buffer, or perhaps this should be expected behaviour for this relatively simple example. I am not sure.

josephdviviano commented 5 months ago

@saleml Just need your official sign off on this before I can merge :)