⚡️ Speed up function mxfp_supported by 62%
#472
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.
📄 62% (0.62x) speedup for
mxfp_supportedinpython/sglang/srt/utils/common.py⏱️ Runtime :
1.48 milliseconds→911 microseconds(best of34runs)📝 Explanation and details
The optimization replaces the
any()generator expression with a direct string membership check, delivering a 62% speedup by eliminating unnecessary overhead.Key optimization: Changed
any(gfx in gcn_arch for gfx in ["gfx95"])to"gfx95" in gcn_arch. Since the list contains only one element ("gfx95"), the generator expression andany()function call are redundant overhead.Why this is faster:
in) is a highly optimized C operation vs Python'sany()functionPerformance impact by test case:
return FalsepathReal-world impact: The function is called from
mxfp4.pyduring quantization configuration setup. While not in a tight loop, this optimization reduces latency during model initialization, particularly beneficial when checking hardware capabilities multiple times across different model components.The optimization maintains identical behavior - both implementations check if "gfx95" appears anywhere in the
gcnArchNamestring, but the optimized version does it more efficiently.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-mxfp_supported-mijuln50and push.