Conversation
norpadon
left a comment
There was a problem hiding this comment.
Accidentally stumbled upon this PR and found a few things to nitpick
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70ed067262
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| let src = &self.suffix_state.as_bytes()[src_start..src_end]; | ||
| let dst = self.conv_state.as_bytes_mut(); | ||
| dst.copy_from_slice(src); |
There was a problem hiding this comment.
dst.copy_from_slice(src);
This used to panic when length mismatch I think.
And now it silently clamps the len, is this behavior expected?
# Conflicts: # crates/backend-uzu/build/common/traitgen.rs # crates/backend-uzu/build/cpu/compiler.rs # crates/backend-uzu/src/backends/cpu/kernel/ssm/ssd_prefill.rs # crates/backend-uzu/src/backends/metal/kernel/matmul/mod.rs # crates/backend-uzu/src/encodable_block/classifier_layer.rs # crates/backend-uzu/src/encodable_block/layer/executables.rs # crates/backend-uzu/src/encodable_block/rope.rs
| pub(super) fn read_float_array<B: Backend, const RANK: usize>( | ||
| tree: &BackendParameterTree<'_, B>, | ||
| pub(super) fn read_float_allocation<B: Backend, const RANK: usize>( | ||
| tree: &BackendParameterTree<B>, | ||
| name: &str, | ||
| expected_data_type: DataType, | ||
| ) -> AudioResult<([usize; RANK], Array<B>)> { |
There was a problem hiding this comment.
Why are you renaming read_float_array to read_float_allocation when this function still returns array?
| let (shape, array) = read_float_array::<B, 1>(tree, name, expected_data_type)?; | ||
| let (shape, allocation) = read_float_allocation::<B, 1>(tree, name, expected_data_type)?; |
There was a problem hiding this comment.
Same as previous one:
This is array, not an allocation
I won't flag more changes that are almost exactly like that, please read the diff before re-requesting review. A change that renames a bunch of functions and variables that were and are still arrays into allocations should never make it's way into a supposedly ready to review pull request.
| pub hidden: &'a mut B::Buffer, | ||
| pub hidden: &'a mut Allocation<B>, | ||
| /// Final output [d_model] | ||
| pub y: &'a mut B::Buffer, | ||
| pub y: &'a mut Allocation<B>, |
There was a problem hiding this comment.
Hidden is not an argument but an intermediate (the comment literally says this + it's fully overwritten in pass a without being read), y should similarly be a return of MoeExpertsSingleDecodeKernels::encode
Also looking at lsp references for this it looks like it's just a dead code (nothing outside of tests encodes this kernel), so it should be just deleted (in a separate prereq pr).
| type Completed: CommandBufferCompleted<CommandBuffer = Self>; | ||
| } | ||
|
|
||
| type CommandBufferBackend<C> = <C as CommandBuffer>::Backend; |
There was a problem hiding this comment.
Let's not have "getter types", things like Allocation<CommandBufferBackend<Self::CommandBuffer>> are much more confusing than Allocation<<Self::CommandBuffer as CommandBuffer>::Backend>
| pub fn encode_copy( | ||
| &mut self, | ||
| src: &B::Buffer, | ||
| src_range: Range<usize>, | ||
| dst: &mut B::Buffer, | ||
| dst_range: Range<usize>, | ||
| src: &Allocation<B>, | ||
| src_range: impl RangeBounds<usize>, | ||
| dst: &mut Allocation<B>, | ||
| dst_range: impl RangeBounds<usize>, | ||
| ) { | ||
| let size = src_range.end - src_range.start; | ||
| debug_assert_eq!(size, dst_range.end - dst_range.start); | ||
| let (src_buffer, src_allocation_range) = src.as_buffer_range(); | ||
| let (dst_buffer, dst_allocation_range) = dst.as_buffer_range(); | ||
| let src_range = resolve_copy_range(src_range, src_allocation_range.len(), "source"); | ||
| let dst_range = resolve_copy_range(dst_range, dst_allocation_range.len(), "destination"); | ||
| let byte_len = src_range.len(); | ||
| assert_eq!(byte_len, dst_range.len(), "copy range lengths must match"); | ||
| assert!(byte_len > 0, "zero-sized copies are not allowed"); | ||
| let src_access_range = src_allocation_range.start + src_range.start..src_allocation_range.start + src_range.end; | ||
| let dst_access_range = dst_allocation_range.start + dst_range.start..dst_allocation_range.start + dst_range.end; | ||
| self.access(&[ | ||
| Access { | ||
| range: src.gpu_address_subrange(src_range.clone()), | ||
| range: src_buffer.gpu_address_subrange(src_access_range), | ||
| flags: AccessFlags::copy_read(), | ||
| }, | ||
| Access { | ||
| range: dst.gpu_address_subrange(dst_range.clone()), | ||
| range: dst_buffer.gpu_address_subrange(dst_access_range), | ||
| flags: AccessFlags::copy_write(), | ||
| }, | ||
| ]); |
There was a problem hiding this comment.
This is very confusing and it implements the same range add thing both here and in backend's implementation, this is not the right way to do things.
| pub down_biases: &'a Allocation<B>, | ||
| /// Hidden buffer [K, d_ff] - intermediate storage (f32) | ||
| pub hidden: &'a mut B::DenseBuffer, | ||
| pub hidden: &'a mut Allocation<B>, |
There was a problem hiding this comment.
I think this should not be an argument any more and but a part of MoeExpertsSingleDecodeKernels::encode
| pub hidden: &'a mut Allocation<B>, | ||
| /// Final output [d_model] | ||
| pub y: &'a mut B::DenseBuffer, | ||
| pub y: &'a mut Allocation<B>, |
There was a problem hiding this comment.
It should be returned by the encode
| pub hidden: &'a mut Allocation<B>, | ||
| pub output: &'a mut Allocation<B>, |
There was a problem hiding this comment.
hidden & the output should be created inside
| let mut x = encoder.allocate_scratch(size_for_shape( | ||
| &[active_row_count, self.config.num_heads, self.config.head_dim], | ||
| self.data_type, | ||
| ))?; | ||
| let bc_shape = [active_row_count, self.config.num_groups, self.config.state_dim]; | ||
| let mut b = encoder.allocate_scratch(size_for_shape(&bc_shape, self.data_type))?; | ||
| let mut c = encoder.allocate_scratch(size_for_shape(&bc_shape, self.data_type))?; |
There was a problem hiding this comment.
I believe x, b, c should be allocated inside run_conv_scan and returned bound in a struct
| let in_proj = self.in_projection.encode(input, active_row_count, encoder)?; | ||
| let mut conv_inputs = | ||
| encoder.allocate_scratch(size_for_shape(&[active_row_count, self.config.conv_dim()], self.data_type))?; | ||
| let mut z = encoder.allocate_scratch(size_for_shape( | ||
| &[active_row_count, self.config.num_heads, self.config.head_dim], | ||
| self.data_type, | ||
| ))?; | ||
| let mut dt = | ||
| encoder.allocate_scratch(size_for_shape(&[active_row_count, self.config.num_heads], self.data_type))?; |
There was a problem hiding this comment.
Looks like in_proj, z and dt should be allocated inside self.run_split_inproj and returned as a struct
| ArrayId::AttentionOutput, | ||
| ArrayId::Main, | ||
| ) | ||
| .expect("Failed to create out-projection kernel"); |
There was a problem hiding this comment.
replace expect with error
| model_dim: usize, | ||
| decoder_layer_loader: &ParameterTree<B::Context>, | ||
| ) -> (Self, Option<B::DenseBuffer>) { | ||
| ) -> (Self, Option<Allocation<B>>) { |
There was a problem hiding this comment.
should return a Result
| ) -> (Self, Option<B::DenseBuffer>) { | ||
| ) -> (Self, Option<Allocation<B>>) { | ||
| if !matches!(layer_type, DecoderLayerType::ShortConv { .. }) { | ||
| panic!("Layer {} marked as non-ShortConv but ShortConv config provided", layer_index); |
There was a problem hiding this comment.
replace panic! with error
| ArrayId::Main, | ||
| ArrayId::SsmInProj, | ||
| ) | ||
| .expect("Failed to create in-projection kernel"); |
There was a problem hiding this comment.
replace expect with error
| ArrayId::AttentionOutput, | ||
| ArrayId::Main, | ||
| ) | ||
| .expect("Failed to create out-projection kernel"); |
There was a problem hiding this comment.
replace expect with error
No description provided.