-
Notifications
You must be signed in to change notification settings - Fork 284
Use BTreeMap for metadata to eliminate hashbrown version conflicts #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Replaces HashMap with BTreeMap for no-std compatibility instead of hashbrown lib which can break if dep versions are different.
|
No we cannot change the public interface for that. But forcing users to use BTreeMap is not OK. If the issue is downstream hashbrown version, then we can upgrade our hashbrown version instead, should be much simpler no ? 0.16 was released a month ago.... |
I am afraid we will have the same issue each time hashbrown version is upgraded. How about we replace hashbrown with BTreeMap conditionally for no_std just like what you have now? I think the user impact is minimal and I can assume there weren't that many consumers of no_std interface because I fixed no_std flag combo recently in #651. I tried changing the metadata type to |
But then we'd have to switch back to |
I am not aware of any near future plan of HashMap to be part of the core. The standard library's HashMap is based on hashbrown internally but the reason std HashMap is not is because it relies on std random generator. So I would say hashbrown should be switched before #651 is released. Otherwise, it will keep breaking people's build every time there is a new hashbrown lib release. With this, we are making safetensors interface more stable. |
|
Wouldn't vendoring safetensors' hashbrown solve this issue ? #[no_std]
pub use hashbrown;Normally, rust doesn't break if multiple versions of a given crate exist in tree... |
I will check if your suggested solution works and will close this PR if does. However, it would have a been a good opportunity to decouple from 3rd party dependency for the API, but it's your call. |
Problem
The serialize() function accepted Option<HashMap<String, String>> in its public API, which exposed hashbrown as a dependency and locked users to a
specific version (0.15.5). This caused type mismatch errors in downstream crates like burn-store that use different hashbrown versions:
Solution
Changed the public API to use BTreeMap<String, String> instead of HashMap:
Why BTreeMap?
Changes
Compatibility
This change decouples safetensors from hashbrown versions while maintaining full functionality and no_std support.
Related to: #651 and tracel-ai/burn#3822