From 5ac20bffc2ba2cbbc20427e484eda9c83f47706d Mon Sep 17 00:00:00 2001 From: Reese Levine Date: Tue, 28 Apr 2026 17:54:23 -0700 Subject: [PATCH 1/2] Update llama-mmap to work with 32-bit wasm and >2GB models --- src/llama-mmap.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/llama-mmap.cpp b/src/llama-mmap.cpp index ccc29c1302e..a16a8aa7f02 100644 --- a/src/llama-mmap.cpp +++ b/src/llama-mmap.cpp @@ -226,7 +226,12 @@ struct llama_file::impl { size_t tell() const { if (fd == -1) { +#ifdef __EMSCRIPTEN__ + // in 32-bit WebAssembly, ftello (64-bit signed return value) is necessary to support files larger than 2GB + off_t ret = ftello(fp); +#else long ret = std::ftell(fp); +#endif if (ret == -1) { throw std::runtime_error(format("ftell error: %s", strerror(errno))); } @@ -244,7 +249,12 @@ struct llama_file::impl { void seek(size_t offset, int whence) const { off_t ret = 0; if (fd == -1) { +#ifdef __EMSCRIPTEN__ + // in 32-bit WebAssembly, fseeko (64-bit signed return value) is necessary to support files larger than 2GB + ret = fseeko(fp, (off_t) offset, whence); +#else ret = std::fseek(fp, (long) offset, whence); +#endif } else { ret = lseek(fd, offset, whence); } From 06e796b016d974932b9807b50531f80dfae22a84 Mon Sep 17 00:00:00 2001 From: Reese Levine Date: Wed, 29 Apr 2026 07:47:09 -0700 Subject: [PATCH 2/2] Update to gguf.cpp style --- src/llama-mmap.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/llama-mmap.cpp b/src/llama-mmap.cpp index a16a8aa7f02..ed572da7fb5 100644 --- a/src/llama-mmap.cpp +++ b/src/llama-mmap.cpp @@ -40,6 +40,14 @@ #include #endif +#ifdef _WIN32 +# define llama_mmap_ftell _ftelli64 +# define llama_mmap_fseek _fseeki64 +#else +# define llama_mmap_ftell ftello +# define llama_mmap_fseek fseeko +#endif + // TODO: consider moving to llama-impl.h if needed in more places #if defined(_WIN32) static std::string llama_format_win_err(DWORD err) { @@ -226,12 +234,7 @@ struct llama_file::impl { size_t tell() const { if (fd == -1) { -#ifdef __EMSCRIPTEN__ - // in 32-bit WebAssembly, ftello (64-bit signed return value) is necessary to support files larger than 2GB - off_t ret = ftello(fp); -#else - long ret = std::ftell(fp); -#endif + off_t ret = llama_mmap_ftell(fp); if (ret == -1) { throw std::runtime_error(format("ftell error: %s", strerror(errno))); } @@ -249,12 +252,7 @@ struct llama_file::impl { void seek(size_t offset, int whence) const { off_t ret = 0; if (fd == -1) { -#ifdef __EMSCRIPTEN__ - // in 32-bit WebAssembly, fseeko (64-bit signed return value) is necessary to support files larger than 2GB - ret = fseeko(fp, (off_t) offset, whence); -#else - ret = std::fseek(fp, (long) offset, whence); -#endif + ret = llama_mmap_fseek(fp, offset, whence); } else { ret = lseek(fd, offset, whence); }