helloadhavan/github_issues huggingface dataset:
Repository: huggingface/transformers
Pull request: More appropriate cuda warmup in resource-constrained hardware

# What does this PR do?

As per the title. See https://github.com/huggingface/transformers/issues/37436 for the edge-case issue


Changed files:
filename: src/transformers/modeling_utils.py
patch: @@ -21,7 +21,6 @@
 import inspect
 import itertools
 import json
-import math
 import os
 import re
 import shutil
@@ -5872,7 +5871,7 @@ def caching_allocator_warmup(model: PreTrainedModel, expanded_device_map: Dict,
     for param_name, device in accelerator_device_map.items():
         param = model.get_parameter_or_buffer(param_name)
         # The dtype of different parameters may be different with composite models or `keep_in_fp32_modules`
-        param_byte_count = math.prod(param.shape) * param.element_size()
+        param_byte_count = param.numel() * param.element_size()
 
         if tp_plan_regex is not None:
             generic_name = re.sub(r"\.\d+\.", ".*.", param_name)
@@ -5885,8 +5884,14 @@ def caching_allocator_warmup(model: PreTrainedModel, expanded_device_map: Dict,
         if device.type == "cuda":
             index = device.index if device.index is not None else torch.cuda.current_device()
             device_memory = torch.cuda.mem_get_info(index)[0]
-            # Allow up to 95% of max device memory
-            byte_count = min(byte_count, int(0.95 * device_memory))
+            # Allow up to (max device memory - 1.2 GiB) in resource-constrained hardware configurations. Trying to reserve more
+            # than that amount might sometimes lead to unecesary cuda OOM, if the last parameter to be loaded on the device is large,
+            # and the remaining reserved memory portion is smaller than the param size -> torch will then try to fully re-allocate all
+            # the param size, instead of using the remaining reserved part, and allocating only the difference, which can lead
+            # to OOM. See https://github.com/huggingface/transformers/issues/37436#issuecomment-2808982161 for more details.
+            # Note that we use an absolute value instead of device proportion here, as a 8GiB device could still allocate too much
+            # if using e.g. 90% of device size, while a 140GiB device would allocate too little
+            byte_count = min(byte_count, int(device_memory - 1.2 * 1024**3))
         # Allocate memory
         _ = torch.empty(byte_count // factor, dtype=torch.float16, device=device, requires_grad=False)
Repository: vercel/next.js
Pull request: build: Update `mdxjs-rs` to `v1`

### What?

Update `mdxjs-rs` to `v1`

### Why?

It's stabilized. https://github.com/wooorm/mdxjs-rs/releases/tag/1.0.0

### How?



Closes PACK-4427

Changed files:
filename: Cargo.lock
patch: @@ -4085,9 +4085,9 @@ checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d"
 
 [[package]]
 name = "markdown"
-version = "1.0.0-alpha.22"
+version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "790c11786cb51d02938e3eb38276575e1658b1dd8555875f5788a40670a33934"
+checksum = "a5cab8f2cadc416a82d2e783a1946388b31654d391d1c7d92cc1f03e295b1deb"
 dependencies = [
  "unicode-id",
 ]
@@ -4124,8 +4124,9 @@ dependencies = [
 
 [[package]]
 name = "mdxjs"
-version = "0.3.4"
-source = "git+https://github.com/kdy1/mdxjs-rs?branch=swc-core-22#a1f16cee2f3350c68a7bebbf74b88e0bac02c9fa"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3218c5892cb3a71ed40c85632d9e05b3a39ce3f9891177d2812ffe75b16f0fef"
 dependencies = [
  "markdown",
  "rustc-hash 2.1.0",

filename: Cargo.toml
patch: @@ -305,7 +305,7 @@ testing = { version = "9.0.0" }
 # Keep consistent with preset_env_base through swc_core
 browserslist-rs = { version = "0.17.0" }
 miette = { version = "5.10.0", features = ["fancy"] }
-mdxjs = "0.3.3"
+mdxjs = "1"
 modularize_imports = { version = "0.82.0" }
 styled_components = { version = "0.110.0" }
 styled_jsx = { version = "0.86.0" }
@@ -435,4 +435,3 @@ wasmer-cache = { git = "https://github.com/kdy1/wasmer", branch = "build-deps" }
 wasmer-compiler-cranelift = { git = "https://github.com/kdy1/wasmer", branch = "build-deps" }
 wasmer-wasix = { git = "https://github.com/kdy1/wasmer", branch = "build-deps" }
 
-mdxjs = { git = "https://github.com/kdy1/mdxjs-rs", branch = "swc-core-22" }
Repository: denoland/deno
Pull request: fix: `rename` watch event missing

This PR ensures that we forward a `rename` event in our file watcher. The rust lib we use combines that with the `modify` event.

This fixes a compatibility issue with Node too, which sends the `rename` event as well.

Fixes https://github.com/denoland/deno/issues/24880

Changed files:
filename: cli/tsc/dts/lib.deno.ns.d.ts
patch: @@ -4149,7 +4149,14 @@ declare namespace Deno {
    * @category File System */
   export interface FsEvent {
     /** The kind/type of the file system event. */
-    kind: "any" | "access" | "create" | "modify" | "remove" | "other";
+    kind:
+      | "any"
+      | "access"
+      | "create"
+      | "modify"
+      | "rename"
+      | "remove"
+      | "other";
     /** An array of paths that are associated with the file system event. */
     paths: string[];
     /** Any additional flags associated with the event. */

filename: ext/node/polyfills/_fs/_fs_watch.ts
patch: @@ -368,6 +368,8 @@ function convertDenoFsEventToNodeFsEvent(
 ): NodeFsEventType {
   if (kind === "create" || kind === "remove") {
     return "rename";
+  } else if (kind === "rename") {
+    return "rename";
   } else {
     return "change";
   }

filename: runtime/ops/fs_events.rs
patch: @@ -14,6 +14,7 @@ use deno_core::op2;
 
 use deno_permissions::PermissionsContainer;
 use notify::event::Event as NotifyEvent;
+use notify::event::ModifyKind;
 use notify::Error as NotifyError;
 use notify::EventKind;
 use notify::RecommendedWatcher;
@@ -71,7 +72,13 @@ impl From<NotifyEvent> for FsEvent {
       EventKind::Any => "any",
       EventKind::Access(_) => "access",
       EventKind::Create(_) => "create",
-      EventKind::Modify(_) => "modify",
+      EventKind::Modify(modify_kind) => match modify_kind {
+        ModifyKind::Name(_) => "rename",
+        ModifyKind::Any
+        | ModifyKind::Data(_)
+        | ModifyKind::Metadata(_)
+        | ModifyKind::Other => "modify",
+      },
       EventKind::Remove(_) => "remove",
       EventKind::Other => "other",
     };

filename: tests/unit/fs_events_test.ts
patch: @@ -70,6 +70,26 @@ Deno.test(
   },
 );
 
+Deno.test(
+  { permissions: { read: true, write: true } },
+  async function watchFsRename() {
+    const testDir = await makeTempDir();
+    const watcher = Deno.watchFs(testDir);
+    async function waitForRename() {
+      for await (const event of watcher) {
+        if (event.kind === "rename") {
+          break;
+        }
+      }
+    }
+    const eventPromise = waitForRename();
+    const file = testDir + "/file.txt";
+    await Deno.writeTextFile(file, "hello");
+    await Deno.rename(file, testDir + "/file2.txt");
+    await eventPromise;
+  },
+);
+
 // TODO(kt3k): This test is for the backward compatibility of `.return` method.
 // This should be removed at 2.0
 Deno.test(
Repository: ggml-org/llama.cpp
Pull request: common: Warn when we can't match samplers for a sampler sequence.

Added a warning if a user tries to specify a sampler via `samplers` (http req) or `--samplers`/`--sampler-seq` with an invalid name or invalid char instead of just silently ignoring it.

I've already come across one project passing incorrect samplers to the API.

I'm happy to change it to throw an exception instead of logging a warning.

Changed files:
filename: common/sampling.cpp
patch: @@ -1,6 +1,7 @@
 #include "sampling.h"
 
 #include "common.h"
+#include "log.h"
 
 #include <cmath>
 #include <unordered_map>
@@ -534,14 +535,16 @@ std::vector<common_sampler_type> common_sampler_types_from_names(const std::vect
         auto sampler = sampler_canonical_name_map.find(name);
         if (sampler != sampler_canonical_name_map.end()) {
             samplers.push_back(sampler->second);
-        } else {
-            if (allow_alt_names) {
-                sampler = sampler_alt_name_map.find(name);
-                if (sampler != sampler_alt_name_map.end()) {
-                    samplers.push_back(sampler->second);
-                }
+            continue;
+        }
+        if (allow_alt_names) {
+            sampler = sampler_alt_name_map.find(name);
+            if (sampler != sampler_alt_name_map.end()) {
+                samplers.push_back(sampler->second);
+                continue;
             }
         }
+        LOG_WRN("%s: unable to match sampler by name '%s'\n", __func__, name.c_str());
     }
 
     return samplers;
@@ -568,6 +571,8 @@ std::vector<common_sampler_type> common_sampler_types_from_chars(const std::stri
         const auto sampler = sampler_name_map.find(c);
         if (sampler != sampler_name_map.end()) {
             samplers.push_back(sampler->second);
+        } else {
+            LOG_WRN("%s: unable to match sampler by char '%c'\n", __func__, c);
         }
     }
Repository: electron/electron
Pull request: fix: ensure version of `xdg-dialog-portal` with `defaultPath` support

Backport of #43570.

See that PR for details.

Notes: Fixed an issue where `defaultPath` did not work for all users on Linux when creating an open file dialog.

Changed files:
filename: patches/chromium/feat_add_support_for_missing_dialog_features_to_shell_dialogs.patch
patch: @@ -272,9 +272,18 @@ index 302147116649575649e44c0fc87e2b0a915db5db..49a4ee5d2a3552b1352c28344e409130
            &SelectFileDialogLinuxKde::OnSelectSingleFolderDialogResponse, this,
            parent, params));
 diff --git a/ui/shell_dialogs/select_file_dialog_linux_portal.cc b/ui/shell_dialogs/select_file_dialog_linux_portal.cc
-index 9e4cc2a3fa2db0397655550a2c6209543f32cbd7..756fe722f802d14edf13fe342479554f5bad2da9 100644
+index 9e4cc2a3fa2db0397655550a2c6209543f32cbd7..8ce7393cd1fcc3782dbefa76d938ee48cd03be7e 100644
 --- a/ui/shell_dialogs/select_file_dialog_linux_portal.cc
 +++ b/ui/shell_dialogs/select_file_dialog_linux_portal.cc
+@@ -39,7 +39,7 @@ constexpr char kMethodStartServiceByName[] = "StartServiceByName";
+ constexpr char kXdgPortalService[] = "org.freedesktop.portal.Desktop";
+ constexpr char kXdgPortalObject[] = "/org/freedesktop/portal/desktop";
+ 
+-constexpr int kXdgPortalRequiredVersion = 3;
++constexpr int kXdgPortalRequiredVersion = 4;
+ 
+ constexpr char kXdgPortalRequestInterfaceName[] =
+     "org.freedesktop.portal.Request";
 @@ -219,6 +219,10 @@ void SelectFileDialogLinuxPortal::SelectFileImpl(
    info_->main_task_runner = base::SequencedTaskRunner::GetCurrentDefault();
    listener_params_ = params;
Repository: electron/electron
Pull request: fix: UvHandle move semantics

Backport of #43615

See that PR for details.


Notes: none.

Changed files:
filename: shell/common/node_bindings.h
patch: @@ -58,8 +58,17 @@ class UvHandle {
   UvHandle() : t_{new T} {}
   ~UvHandle() { reset(); }
 
-  UvHandle(UvHandle&&) = default;
-  UvHandle& operator=(UvHandle&&) = default;
+  explicit UvHandle(UvHandle&& that) {
+    t_ = that.t_;
+    that.t_ = nullptr;
+  }
+
+  UvHandle& operator=(UvHandle&& that) {
+    reset();
+    t_ = that.t_;
+    that.t_ = nullptr;
+    return *this;
+  }
 
   UvHandle(const UvHandle&) = delete;
   UvHandle& operator=(const UvHandle&) = delete;
Repository: ggml-org/llama.cpp
Pull request: musa: remove nrows_x in mul_mat_q_process_tile

*Make sure to read the [contributing guidelines](https://github.com/ggml-org/llama.cpp/blob/master/CONTRIBUTING.md) before submitting a PR*

Fix a new warning detected by our internal CI.

Changed files:
filename: ggml/src/ggml-cuda/mmq.cuh
patch: @@ -2522,7 +2522,7 @@ template <ggml_type type, int mmq_x, int nwarps, bool need_check, bool fixup>
 static __device__ __forceinline__ void mul_mat_q_process_tile(
         const char * __restrict__ x, const int offset_x, const int * __restrict__ y,
         const int * __restrict__ ids_dst, float * __restrict__ dst, float * __restrict__ tmp_fixup,
-        const int nrows_x, const int stride_row_x, const int ncols_y, const int stride_col_dst,
+        const int stride_row_x, const int ncols_y, const int stride_col_dst,
         const int tile_x_max_i, const int tile_y_max_j, const int kb0_start, const int kb0_stop) {
 
     constexpr int              qk         = ggml_cuda_type_traits<type>::qk;
@@ -2689,7 +2689,7 @@ static __global__ void mul_mat_q(
 
         constexpr bool fixup = false;
         mul_mat_q_process_tile<type, mmq_x, nwarps, need_check, fixup>
-            (x, offset_x, y + offset_y, ids_dst_shared, dst + offset_dst, tmp_fixup, nrows_x, stride_row_x, ncols_y, stride_col_dst,
+            (x, offset_x, y + offset_y, ids_dst_shared, dst + offset_dst, tmp_fixup, stride_row_x, ncols_y, stride_col_dst,
              tile_x_max_i, tile_y_max_j, 0, ncols_x/qk);
         return;
     }
@@ -2767,7 +2767,7 @@ static __global__ void mul_mat_q(
 
         constexpr bool fixup = false; // All but (potentially) the last iterations write their data to dst rather than the fixup buffer.
         mul_mat_q_process_tile<type, mmq_x, nwarps, need_check, fixup>
-            (x, offset_x, y + offset_y, ids_dst_shared, dst + offset_dst, tmp_fixup, nrows_x, stride_row_x, ncols_y, stride_col_dst,
+            (x, offset_x, y + offset_y, ids_dst_shared, dst + offset_dst, tmp_fixup, stride_row_x, ncols_y, stride_col_dst,
              tile_x_max_i, tile_y_max_j, kb0_start, kb0_stop);
 
         kbc += blocks_per_ne00;
@@ -2834,7 +2834,7 @@ static __global__ void mul_mat_q(
 
     constexpr bool fixup = true; // Last index writes its data to fixup buffer to avoid data races with other blocks.
     mul_mat_q_process_tile<type, mmq_x, nwarps, need_check, fixup>
-        (x, offset_x, y + offset_y, ids_dst_shared, dst + offset_dst, tmp_fixup, nrows_x, stride_row_x, ncols_y, stride_col_dst,
+        (x, offset_x, y + offset_y, ids_dst_shared, dst + offset_dst, tmp_fixup, stride_row_x, ncols_y, stride_col_dst,
          tile_x_max_i, tile_y_max_j, kb0_start, kb0_stop);
 }
Repository: vercel/next.js
Pull request: fix(turbopack): Fix sourcemap path on windows

### What?

Fix source map path on windows, by fixing `url_to_file` function

Note: This PR is based on https://github.com/vercel/next.js/pull/78430 by @JustSuperHuman

### Why?

### How?

 - Closes PACK-4217
 - Closes PACK-3924
 - Closes https://github.com/vercel/next.js/issues/72789

Changed files:
filename: turbopack/crates/turbo-tasks-fs/src/lib.rs
patch: @@ -1288,6 +1288,10 @@ impl FileSystemPath {
     /// None when the joined path would leave the filesystem root.
     #[turbo_tasks::function]
     pub async fn try_join(&self, path: RcStr) -> Result<Vc<FileSystemPathOption>> {
+        // TODO(PACK-3279): Remove this once we do not produce invalid paths at the first place.
+        #[cfg(target_os = "windows")]
+        let path = path.replace('\\', "/");
+
         if let Some(path) = join_path(&self.path, &path) {
             Ok(Vc::cell(Some(
                 Self::new_normalized(*self.fs, path.into())

filename: turbopack/crates/turbo-tasks-fs/src/util.rs
patch: @@ -138,6 +138,7 @@ pub fn extract_disk_access<T>(value: io::Result<T>, path: &Path) -> Result<Optio
     }
 }
 
+#[cfg(not(target_os = "windows"))]
 pub async fn uri_from_file(root: Vc<FileSystemPath>, path: Option<&str>) -> Result<String> {
     let root_fs = root.fs();
     let root_fs = &*Vc::try_resolve_downcast_type::<DiskFileSystem>(root_fs)
@@ -162,3 +163,34 @@ pub async fn uri_from_file(root: Vc<FileSystemPath>, path: Option<&str>) -> Resu
         .join("/")
     ))
 }
+
+#[cfg(target_os = "windows")]
+pub async fn uri_from_file(root: Vc<FileSystemPath>, path: Option<&str>) -> Result<String> {
+    let root_fs = root.fs();
+    let root_fs = &*Vc::try_resolve_downcast_type::<DiskFileSystem>(root_fs)
+        .await?
+        .context("Expected root to have a DiskFileSystem")?
+        .await?;
+
+    let sys_path = root_fs
+        .to_sys_path(match path {
+            Some(path) => root.join(path.into()),
+            None => root,
+        })
+        .await?;
+
+    let raw_path = sys_path.to_string_lossy().to_string();
+    let normalized_path = raw_path.replace('\\', "/");
+
+    let mut segments = normalized_path.split('/');
+
+    let first = segments.next().unwrap_or_default(); // e.g., "C:"
+    let encoded_path = std::iter::once(first.to_string()) // keep "C:" intact
+        .chain(segments.map(|s| urlencoding::encode(s).into_owned()))
+        .collect::<Vec<_>>()
+        .join("/");
+
+    let uri = format!("file:///{}", encoded_path);
+
+    Ok(uri)
+}
Repository: electron/electron
Pull request: fix: UvHandle move semantics

#### Description of Change

Fix move semantics for UvHandle. This fixes a potential issue in #43561.

#### Checklist

- [x] PR description included and stakeholders cc'd
- [x] `npm test` passes
- [x] [PR release notes](https://github.com/electron/clerk/blob/main/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/main/README.md#examples).

#### Release Notes

Notes: none.

Changed files:
filename: shell/common/node_bindings.h
patch: @@ -62,8 +62,17 @@ class UvHandle {
   UvHandle() : t_{new T} {}
   ~UvHandle() { reset(); }
 
-  UvHandle(UvHandle&&) = default;
-  UvHandle& operator=(UvHandle&&) = default;
+  explicit UvHandle(UvHandle&& that) {
+    t_ = that.t_;
+    that.t_ = nullptr;
+  }
+
+  UvHandle& operator=(UvHandle&& that) {
+    reset();
+    t_ = that.t_;
+    that.t_ = nullptr;
+    return *this;
+  }
 
   UvHandle(const UvHandle&) = delete;
   UvHandle& operator=(const UvHandle&) = delete;
Repository: ggml-org/llama.cpp
Pull request: sampling: make top_n_sigma no-op at <=0 rather than <0

This changes the behavior of the recently-added `top_n_sigma` sampler to a short-circuit no-op state at values <= 0 rather than < 0. The rationale for this change is as follows:

* The current behavior of `top_n_sigma` == 0 is redundant as it is a more roundabout way to achieve greedy decoding, which already has other means of being specified, i.e. `top_k` == 1
* `top_n_sigma` == 0 represents no-op rather than greedy decoding in other existing tooling (i.e. [text-generation-webui](https://github.com/oobabooga/text-generation-webui/blob/ace8afb825c80925ed21ab26dbf66b538ab06285/modules/sampler_hijack.py#L570), [aphrodite-engine](https://github.com/aphrodite-engine/aphrodite-engine/blob/22427602ebd45652a0ea323dad3959430c6db352/aphrodite/common/sampling_params.py#L151-L155), [koboldcpp](https://github.com/LostRuins/koboldcpp/blob/17cbf9fd49418248210e97136b9b2eaf00d2c8b2/gpttype_adapter.cpp#L1415), [YALS](https://github.com/theroyallab/YALS/blob/7008a12e33c9bb9e9b9e549ac61372ec95279744/bindings/bindings.ts#L567)), so this would keep the interface consistent for frontend developers

Changed files:
filename: src/llama-sampling.cpp
patch: @@ -1750,7 +1750,7 @@ static const char * llama_sampler_top_n_sigma_name(const struct llama_sampler *
 static void llama_sampler_top_n_sigma_apply(struct llama_sampler * smpl, llama_token_data_array * cur_p) {
     const auto * ctx = (llama_sampler_top_n_sigma *) smpl->ctx;
 
-    if (ctx->n < 0.0f) {
+    if (ctx->n <= 0.0f || cur_p->size <= 1) {
         return;
     }
 

filename: tests/test-sampling.cpp
patch: @@ -360,7 +360,7 @@ int main(void) {
     test_dry({0.2f, 0.2f, 0.2f, 0.2f, 0.2f}, {0, 1, 2, 3, 4, 0, 1}, {0.2f, 0.2f, 0.2f, 0.2f, 0.2f}, 1.0f, 1.1f, 4, 7, {});
 
     test_top_n_sigma({0.1f, 0.2f, 0.3f, 0.4f}, {0.571429f, 0.428571f, 0.0f, 0.0f}, 1.00f);
-    test_top_n_sigma({0.1f, 0.2f, 0.3f, 0.4f}, {1.0f, 0.0f, 0.0f, 0.0f}, 0.00f);
+    test_top_n_sigma({0.1f, 0.2f, 0.3f, 0.4f}, {0.4f, 0.3f, 0.2f, 0.1f}, 0.00f); // top_n_sigma == 0 now represents a no-op rather than greedy decoding as of PR#13345
     test_top_n_sigma({0.1f, 0.2f, 0.3f, 0.4f}, {0.4f, 0.3f, 0.2f, 0.1f}, 3.00f);
 
     test_sampler_queue(10000, "k", 10000, 1.0f, 1.0f);
Repository: facebook/react
Pull request: Add exports field to react-dom (including configuring Cloudflare and Deno)

This configures the exports field for react-dom.

Notably there are some conditions for the /server entry point where we pick the export based on environments. Most environments now support Web Streams which is preferred in those environments.

We already do this using the "browser" field so the "browser" condition applies here too.

I also specified "worker" explicitly since this is for Service Workers and those are often targeted with Webpack's "webworker" target, which is also [what Cloudflare currently recommends](https://developers.cloudflare.com/workers/cli-wrangler/webpack). I don't think this is necessary because Webpack includes the "browser" field for this case. However, it seems more accurate. Although I'm not sure if this would break if you use a Worker in Node.js.

I also added "deno" but Deno is a bit special because this only works if you run with the node compatibility on since otherwise you have to specify absolute URLs for the imports anyway. Currently the node compatibility doesn't work well from real ESM and the built-in JSX support doesn't work outside of real ESM. So this is a bit of a mess.

I wasn't able to add fixtures and test any of this yet. It ended up being kind of messy and a lot of work to create a real environment. This seems like the aspirational goal we want though and to avoid breaking changes it seems worth landing. For example, Deno in Node compat mode should still use the browser build.


Changed files:
filename: packages/react-dom/package.json
patch: @@ -38,6 +38,19 @@
     "cjs/",
     "umd/"
   ],
+  "exports": {
+    ".": "./index.js",
+    "./server": {
+      "deno": "./server.browser.js",
+      "worker": "./server.browser.js",
+      "browser": "./server.browser.js",
+      "default": "./server.node.js"
+    },
+    "./profiling": "./profiling.js",
+    "./test-utils": "./test-utils.js",
+    "./package.json": "./package.json",
+    "./": "./"
+  },
   "browser": {
     "./server.js": "./server.browser.js"
   },
Repository: nodejs/node
Pull request: tools: enable linter for `tools/icu/**`

Refs: https://github.com/nodejs/node/pull/55618#issuecomment-2464222278

Changed files:
filename: eslint.config.mjs
patch: @@ -50,7 +50,6 @@ export default [
       'test/addons/??_*',
       'test/fixtures/**',
       'tools/github_reporter/**',
-      'tools/icu/**',
     ],
   },
   // #endregion
Repository: ggml-org/llama.cpp
Pull request: sampling: Don't consider -infinity values in top_n_sigma

This PR makes `top_n_sigma` work even when the logits contain `-inf` values, which may happen eg if `logit_bias` is used to set some token IDs to false.

Changed files:
filename: src/llama-sampling.cpp
patch: @@ -1757,20 +1757,28 @@ static void llama_sampler_top_n_sigma_apply(struct llama_sampler * smpl, llama_t
     // find max logit and calculate mean
     float max = cur_p->data[0].logit;
     float logits_sum = 0;
+    size_t valid_count = 0;
     for (size_t i = 0; i < cur_p->size; ++i) {
-        if (cur_p->data[i].logit > max) {
-            max = cur_p->data[i].logit;
+        // Only count non-negative infinity values
+        if (cur_p->data[i].logit != -INFINITY) {
+            if (cur_p->data[i].logit > max) {
+                max = cur_p->data[i].logit;
+            }
+            logits_sum += cur_p->data[i].logit;
+            valid_count++;
         }
-        logits_sum += cur_p->data[i].logit;
     }
-    float mean = logits_sum/cur_p->size;
+    float mean = valid_count > 0 ? logits_sum/valid_count : 0;
 
     // calculate standard deviation
     float acc = 0;
     for (size_t i = 0; i < cur_p->size; ++i) {
-        acc += pow(cur_p->data[i].logit - mean, 2);
+        // Skip -infinity in std calculation
+        if (cur_p->data[i].logit != -INFINITY) {
+            acc += pow(cur_p->data[i].logit - mean, 2);
+        }
     }
-    float std = sqrt(acc/cur_p->size);
+    float std = valid_count > 0 ? sqrt(acc/valid_count) : 0;
 
     //apply mask
     for (size_t i = 0; i < cur_p->size; ++i) {