Conversation
Implements GPU-native operations to eliminate H2D/D2H transfer overhead: CUDA Kernels: - layer_norm_simple: LayerNorm without learnable params - modulate: AdaLN-style modulation (x * (1 + scale) + shift) - gated_residual: Gated residual connection - scale_tensor: Scalar multiplication - concat_axis1/split_axis1: Tensor manipulation along axis 1 - apply_rope: Rotary position embedding - layer_norm_modulate: Fused LayerNorm + modulation - add_broadcast: Broadcasting addition Fixes: - batched_matmul now uses cuBLAS sgemm_strided_batched - Proper row-major to column-major conversion for cuBLAS Tests: - NumPy validation tests for all new kernels - 3D and 4D batched matmul tests Closes #187 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update blocks.py to use GPU-native operations: - Replace NumPy gated residual with gpu_gated_residual - Replace NumPy layer norm with gpu_layer_norm - Replace NumPy modulate with gpu_modulate - Use gpu_concat_axis1 and gpu_split_axis1 for tensor ops - Update attention.py layer_norm to use GPU-native kernel - Add benchmark script for PyGPUkit vs Diffusers comparison Performance analysis shows matmul operations are fast (30-70 TFLOPS) but significant overhead from: - GC overhead (6.6s) from temporary GPUArray allocations - reshape_copy operations (5.7s) Further optimization requires reducing temporary allocations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Changes
CUDA Kernels (
native/ops/nn/diffusion/flux_kernels.cuh)layer_norm_simple_kernel- Simple layer normalization (no affine)modulate_kernel- AdaLN modulation:y = x * (1 + scale) + shiftgated_residual_kernel- Gated residual:y = residual + gate * valuescale_tensor_kernel- Element-wise scalingconcat_axis1_kernel/split_axis1_kernel- Axis-1 concatenation/splittingadd_broadcast_kernel- Broadcasting additionlayer_norm_modulate_fused_kernel- Fused LayerNorm + modulationcuBLAS Integration (
native/ops/matmul/batched.cu)batched_matmul_fp32using cuBLAS sgemm_strided_batchedPython API Updates (
src/pygpukit/diffusion/models/flux/ops.py)Test plan
tests/test_flux_kernels.py)Benchmark
Run
python -m pytest tests/test_flux_kernels.py -vto verify:Closes #187
🤖 Generated with Claude Code