Someone's been messing with Python's floating point subnormals
A technical issue with Python packages, particularly from Huggingface Transformers, was identified, where the `gevent` library altered floating point behavior, leading to potential numerical inaccuracies in applications.
Read original articleThe article discusses a technical issue encountered while using Python packages, particularly those from Huggingface Transformers, which resulted in warnings related to floating point subnormals. The author discovered that a small number of Python packages were compiled with the `-ffast-math` compiler option, which alters floating point behavior by treating subnormal numbers as zero. This can lead to incorrect numerical results in applications relying on standard floating point operations. The author traced the problem to the `gevent` library, which was found to be setting the FTZ/DAZ flags, causing the unexpected behavior. To investigate further, the author analyzed the top 25% of projects on PyPI by download count to identify other libraries that might have similar issues. The article highlights the challenges of ensuring numerical accuracy in Python applications and the potential pitfalls of using certain compiler optimizations without understanding their implications.
- A small number of Python packages can cause incorrect numerical results due to the `-ffast-math` compiler option.
- The `gevent` library was identified as a culprit for altering floating point behavior.
- The author analyzed the top 25% of PyPI projects to find other libraries with similar issues.
- The article emphasizes the importance of understanding compiler optimizations in numerical computing.
- Users should be cautious when using libraries that may inadvertently affect floating point calculations.
Related
Y292B Bug
The Y292B bug is a potential timekeeping issue in Unix systems due to a rollover in the year 292,277,026,596. Solutions involve using dynamic languages or GNU Multiple Precision Arithmetic Library in C, emphasizing the need for kernel-level fixes.
Fear of over-engineering has killed engineering altogether
The article critiques the tech industry's focus on speed over engineering rigor, advocating for "Napkin Math" and Fermi problems to improve decision-making and project outcomes through basic calculations.
The Trouble with __all__
The article addresses challenges with Python's `__all__` attribute for public APIs, introducing a `ModuleWrapper` class and the Tach tool for enforcing strict interfaces and improving module boundary clarity.
Clang vs. Clang
The blog post critiques compiler optimizations in Clang, arguing they often introduce bugs and security vulnerabilities, diminish performance gains, and create timing channels, urging a reevaluation of current practices.
A Knownbits Abstract Domain for the Toy Optimizer, Correctly
The article details the Knownbits Abstract Domain's implementation in PyPy's Toy Optimizer, enhancing integer operation optimizations through bit analysis, property-based testing, and improving static analysis for efficient code generation.
2004 - GCC 3.4: - Refinements and Extensions: Additional optimizations added, including better handling of subnormal numbers and more aggressive operation reordering.
2007 - GCC 4.2: - Introduction of Related Flags: `-funsafe-math-optimizations` flag introduced, offering more granular control over specific optimizations.
2010 - GCC 4.5: - Improvements in Vectorization: Enhanced vectorization capabilities, particularly for SIMD hardware using SSE and AVX instruction sets.
2013 - GCC 4.8: - More Granular Control: Introduction of flags like `-fno-math-errno`, improving efficiency by assuming mathematical functions do not set `errno`.
2017 - GCC 7.0: - Enhanced Complex Number Optimizations: Improved performance for complex number arithmetic, benefiting scientific and engineering applications.
2021 - GCC 11.0: - Better Support for Modern Hardware: Optimizations leveraging modern CPU architectures and instruction sets like AVX-512.
2024 - GCC 13.0 (Experimental): - Experimental Features: Additional optimizations focused on new CPU features and better handling of edge cases.
Sources: - GCC documentation archives - Release notes from various GCC versions - [GCC Wiki](https://gcc.gnu.org/wiki/) - [Krister Walfridsson's blog](https://kristerw.github.io)
I remember this one because of this part:
> Unbeknownst to me, even with --dry-run pip will execute arbitrary code found in the package's setup.py. In fact, merely asking pip to download a package can execute arbitrary code (see pip issues 7325 and 1884 for more details)! So when I tried to dry-run install almost 400K Python packages, hilarity ensued. I spent a long time cleaning up the mess, and discovered some pretty poor setup.py practices along the way. But hey, at least I got two free pictures of anime catgirls, deposited directly into my home directory. Convenient!
This made me chuckle
Related
Y292B Bug
The Y292B bug is a potential timekeeping issue in Unix systems due to a rollover in the year 292,277,026,596. Solutions involve using dynamic languages or GNU Multiple Precision Arithmetic Library in C, emphasizing the need for kernel-level fixes.
Fear of over-engineering has killed engineering altogether
The article critiques the tech industry's focus on speed over engineering rigor, advocating for "Napkin Math" and Fermi problems to improve decision-making and project outcomes through basic calculations.
The Trouble with __all__
The article addresses challenges with Python's `__all__` attribute for public APIs, introducing a `ModuleWrapper` class and the Tach tool for enforcing strict interfaces and improving module boundary clarity.
Clang vs. Clang
The blog post critiques compiler optimizations in Clang, arguing they often introduce bugs and security vulnerabilities, diminish performance gains, and create timing channels, urging a reevaluation of current practices.
A Knownbits Abstract Domain for the Toy Optimizer, Correctly
The article details the Knownbits Abstract Domain's implementation in PyPy's Toy Optimizer, enhancing integer operation optimizations through bit analysis, property-based testing, and improving static analysis for efficient code generation.