Torch Implementation of the Sampler on the frog branch + torch eval script + torch implementation bugfix + tests #72
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR does the following:
eq_bench
- (For documentation purposes): Specifically, the existing implementation has issues with how the q k v
dtypes
are handled after RoPE. In Jax, the first time the kvcache is populated (whencur_pos = 0
), the keys and values are in float32. Forcur_pos != 0
, the cache is in bf16 and jax automatically converts to fp32 to performxq @ k
in fp32. For torch, even though post-RoPE keys are in fp32, the cache buffers are in bf16 and theupdate
method will return bf16. So we will need to explicitly cast to fp32 to match the jax implementation.- Because of bf16, jax, jit and torch things, tests are done in fp32 with jit except for attention which compares the torch version with the non jit jax version.
- Note: The
test_each_layer
test might fail around 3% of the time due to 'unluckily' initialised inputs. Even so, this fails with < 0.5% mismatched elements (the number of mismatched elements is < 5).main.py
Let me know if a PR to main is preferred and I'll update!