News for hackers. Stuff that matters.
Re:Llama2.rs: One-file Rust implementation of Llama2 by CameronNemo on Saturday August 05, 2023 @06:46PM (#37016983)
This is my first Rust project, so if you are an expert I would love a code review!

Seeing a few uses of `unsafe`, a few of `expect`. Wonder if you can mmap the binary model in without unsafe??

Re:Llama2.rs: One-file Rust implementation of Llama2 by tredre3 on Saturday August 05, 2023 @07:28PM (#37017270)
> Wonder if you can mmap the binary model in without unsafe??

Some operating systems do provide the proper guarantees to make mmap safe, but Rust decided it would be best to assume it's unsafe and maintain a uniform API. Which is probably a good call, it is notoriously difficult to get a readonly mmap to be entirely safe on Linux.

https://docs.rs/mmap-rs/latest/mmap_rs/struct.MmapOptions.ht...

Re:Llama2.rs: One-file Rust implementation of Llama2 by WhyNotHugo on Sunday August 06, 2023 @04:19AM (#37019973)
It’s not safe under Rust’s definition of safe.

If you map the file into readonly memory and than get references to it, the underlying memory can mutate (eg: by modifying the file itself).