Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: simple utility to get timestep count #34

Merged
merged 3 commits into from
Aug 29, 2024

Conversation

callumtilbury
Copy link
Contributor

From discussions in #33.

Demo:

import flashbax as fbx
import jax.numpy as jnp
from flashbax.utils import get_timestep_count

buffer = fbx.make_flat_buffer(
    max_length=10,
    min_length=1,
    sample_batch_size=1,
    add_batch_size=2,
    add_sequences=False,
)

timestep = {"obs": jnp.array([1.0])}

state = buffer.init(timestep)

for i in range(10):
    timestep = {
        "obs": jnp.tile(jnp.array([i], dtype=jnp.float32), (2, 1)),
    }
    state = buffer.add(state, timestep)

    print("Timestep count =", get_timestep_count(state))

Output:

Timestep count = 2
Timestep count = 4
Timestep count = 6
Timestep count = 8
Timestep count = 10
Timestep count = 10
Timestep count = 10
Timestep count = 10
Timestep count = 10
Timestep count = 10

@EdanToledo
Copy link
Contributor

@callumtilbury I'm happy with this but can we have a small test that it is jittable - i dont even really need the test to be in the codebase, i just want confirmation.

@callumtilbury
Copy link
Contributor Author

@EdanToledo indeed, previously confirmed jittable!

#33 (comment)

@EdanToledo
Copy link
Contributor

then im happy

@EdanToledo EdanToledo enabled auto-merge August 29, 2024 14:36
Copy link
Contributor

@EdanToledo EdanToledo left a comment

Choose a reason for hiding this comment

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

LGTM!

@EdanToledo EdanToledo merged commit e03c4af into main Aug 29, 2024
3 checks passed
@EdanToledo EdanToledo deleted the feat/total_timestep_util branch August 29, 2024 14:37
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.

2 participants