Skip to content

Add safety note around unsafe for mmap2 - #18

Merged
alvarobartt merged 1 commit into
mainfrom
add-safety-note
Sep 25, 2026
Merged

alvarobartt merged 1 commit into
mainfrom
add-safety-note

Conversation

@alvarobartt

@alvarobartt alvarobartt commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Description

This PR adds a safety note as // SAFETY: ... above the unsafe usage for let vb = unsafe { VarBuilder::from_mmaped_safetensors(&[weights], model_dtype, &device)? }; which is using mmap2 to load the Safetensors weights into memory and is considered unsafe by design.

More information at https://github.com/huggingface/candle/blob/66a8cf184a5a519671454066b1b9efd446ec9f5c/candle-nn/src/var_builder.rs#L636-L649 for the candle reference, and at https://github.com/RazrFalcon/memmap2-rs/blob/a02e2a/src/lib.rs#L135-L165 for the mmap2 reference.

Thanks to @ositanachi and @muralivp from Microsoft for raising it!

@alvarobartt
alvarobartt merged commit 580e5c9 into main Sep 25, 2026
1 of 2 checks passed
@alvarobartt
alvarobartt deleted the add-safety-note branch September 25, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant