helloadhavan/github_issues huggingface dataset:
Repository: nodejs/node
Pull request: lib: fix DOMException subclass support

Fixes https://github.com/nodejs/node/issues/59677

Changed files:
filename: lib/internal/per_context/domexception.js
patch: @@ -60,7 +60,6 @@ const disusedNamesSet = new SafeSet()
   .add('NoDataAllowedError')
   .add('ValidationError');
 
-let DOMExceptionPrototype;
 // The DOMException WebIDL interface defines that:
 // - ObjectGetPrototypeOf(DOMException) === Function.
 // - ObjectGetPrototypeOf(DOMException.prototype) === Error.prototype.
@@ -75,7 +74,8 @@ class DOMException {
     // internal slot.
     // eslint-disable-next-line no-restricted-syntax
     const self = new Error();
-    ObjectSetPrototypeOf(self, DOMExceptionPrototype);
+    // Use `new.target.prototype` to support DOMException subclasses.
+    ObjectSetPrototypeOf(self, new.target.prototype);
     self[transfer_mode_private_symbol] = kCloneable;
 
     if (options && typeof options === 'object') {
@@ -158,7 +158,7 @@ class DOMException {
   }
 }
 
-DOMExceptionPrototype = DOMException.prototype;
+const DOMExceptionPrototype = DOMException.prototype;
 ObjectSetPrototypeOf(DOMExceptionPrototype, ErrorPrototype);
 ObjectDefineProperties(DOMExceptionPrototype, {
   [SymbolToStringTag]: { __proto__: null, configurable: true, value: 'DOMException' },

filename: test/parallel/test-domexception-subclass.js
patch: @@ -0,0 +1,55 @@
+'use strict';
+
+require('../common');
+const assert = require('assert');
+
+class MyDOMException extends DOMException {
+  ownProp;
+  #reason;
+
+  constructor() {
+    super('my message', 'NotFoundError');
+    this.ownProp = 'bar';
+    this.#reason = 'hello';
+  }
+
+  get reason() {
+    return this.#reason;
+  }
+}
+
+const myException = new MyDOMException();
+// Verifies the prototype chain
+assert(myException instanceof MyDOMException);
+assert(myException instanceof DOMException);
+assert(myException instanceof Error);
+// Verifies [[ErrorData]]
+assert(Error.isError(myException));
+
+// Verifies subclass properties
+assert(Object.hasOwn(myException, 'ownProp'));
+assert(!Object.hasOwn(myException, 'reason'));
+assert.strictEqual(myException.reason, 'hello');
+
+// Verifies error properties
+assert.strictEqual(myException.name, 'NotFoundError');
+assert.strictEqual(myException.code, 8);
+assert.strictEqual(myException.message, 'my message');
+assert.strictEqual(typeof myException.stack, 'string');
+
+// Verify structuredClone only copies known error properties.
+const cloned = structuredClone(myException);
+assert(!(cloned instanceof MyDOMException));
+assert(cloned instanceof DOMException);
+assert(cloned instanceof Error);
+assert(Error.isError(cloned));
+
+// Verify custom properties
+assert(!Object.hasOwn(cloned, 'ownProp'));
+assert.strictEqual(cloned.reason, undefined);
+
+// Verify cloned error properties
+assert.strictEqual(cloned.name, 'NotFoundError');
+assert.strictEqual(cloned.code, 8);
+assert.strictEqual(cloned.message, 'my message');
+assert.strictEqual(cloned.stack, myException.stack);
Repository: ollama/ollama
Pull request: update welcome prompt in windows to `llama3`


Changed files:
filename: app/ollama_welcome.ps1
patch: @@ -4,5 +4,5 @@ write-host "Welcome to Ollama!"
 write-host ""
 write-host "Run your first model:"
 write-host ""
-write-host "`tollama run llama2"
+write-host "`tollama run llama3"
 write-host ""
\ No newline at end of file
Repository: ggml-org/llama.cpp
Pull request: Cmdline arg -to changes http read timeout from current 600sec default

llama-server has a hard-coded HTTP timeout of 300 seconds (the http library default). If the prompt and input files take longer than this timeout to process, the connection times out and is dropped, the WebUI gets out of sync, etc.

It is easy to exceed 300 (or 600) seconds on consumer hardware.

This PR reads the --timeout (-to) command-line argument. The default for --timeout is 600 seconds, twice as long as the http library's 300 seconds. The value of --timeout always overwrites the http library's default now. As a result, twice as long is now available by default. More is often needed though.

Huge timeouts can now be set with --timeout, circumventing this failure.

Note: Model unloading won't complete if cli->send() is active. A huge --timeout can make unloading impractical.

Changed files:
filename: tools/server/server-models.cpp
patch: @@ -662,7 +662,10 @@ server_http_res_ptr server_models::proxy_request(const server_http_req & req, co
             req.path,
             req.headers,
             req.body,
-            req.should_stop);
+            req.should_stop,
+            base_params.timeout_read,
+            base_params.timeout_write
+            );
     return proxy;
 }
 
@@ -950,13 +953,18 @@ server_http_proxy::server_http_proxy(
         const std::string & path,
         const std::map<std::string, std::string> & headers,
         const std::string & body,
-        const std::function<bool()> should_stop) {
+        const std::function<bool()> should_stop,
+        int32_t timeout_read,
+        int32_t timeout_write
+        ) {
     // shared between reader and writer threads
     auto cli  = std::make_shared<httplib::Client>(host, port);
     auto pipe = std::make_shared<pipe_t<msg_t>>();
 
     // setup Client
     cli->set_connection_timeout(0, 200000); // 200 milliseconds
+    cli->set_write_timeout(timeout_read, 0); // reversed for cli (client) vs srv (server)
+    cli->set_read_timeout(timeout_write, 0);
     this->status = 500; // to be overwritten upon response
     this->cleanup = [pipe]() {
         pipe->close_read();

filename: tools/server/server-models.h
patch: @@ -183,7 +183,10 @@ struct server_http_proxy : server_http_res {
                       const std::string & path,
                       const std::map<std::string, std::string> & headers,
                       const std::string & body,
-                      const std::function<bool()> should_stop);
+                      const std::function<bool()> should_stop,
+                      int32_t timeout_read,
+                      int32_t timeout_write
+                      );
     ~server_http_proxy() {
         if (cleanup) {
             cleanup();
Repository: ggml-org/llama.cpp
Pull request: vulkan: fix topk_moe_sigmoid_norm_bias failures in GLM-4.6

Should fix #18563.

Changed files:
filename: ggml/src/ggml-vulkan/vulkan-shaders/topk_moe.comp
patch: @@ -101,6 +101,10 @@ void main() {
     const uint lane = gl_SubgroupInvocationID;
 
     float probs[experts_per_thread];
+    [[unroll]]
+    for (int i = 0; i < experts_per_thread; i++) {
+        probs[i] = -INFINITY;
+    }
 
     [[unroll]]
     for (uint i = 0; i < n_experts; i += WARP_SIZE) {
@@ -112,8 +116,9 @@ void main() {
         softmax_warp_inplace(probs, n_experts, lane, nexperts_use_push);
     } else if (gating_func == GATING_FUNC_SIGMOID) {
         [[unroll]]
-        for (int i = 0; i < experts_per_thread; i++) {
-            probs[i] = 1.f / (1.f + exp(-probs[i]));
+        for (uint i = 0; i < n_experts; i += WARP_SIZE) {
+            const uint expert = i + lane;
+            probs[i / WARP_SIZE] = (n_experts % WARP_SIZE == 0 || expert < n_experts) ? 1.f / (1.f + exp(-probs[i / WARP_SIZE])) : -INFINITY;
         }
     }
 
@@ -150,11 +155,11 @@ void main() {
         uint   max_expert = lane;
 
         [[unroll]]
-        for (int i = 1; i < experts_per_thread; i++) {
-            const uint expert = lane + i * WARP_SIZE;
-            if ((n_experts % WARP_SIZE == 0 || expert < n_experts) && selection_probs[i] > max_val_s) {
-                max_val    = probs[i];
-                max_val_s  = selection_probs[i];
+        for (uint i = WARP_SIZE; i < n_experts; i += WARP_SIZE) {
+            const uint expert = i + lane;
+            if ((n_experts % WARP_SIZE == 0 || expert < n_experts) && selection_probs[i / WARP_SIZE] > max_val_s) {
+                max_val    = probs[i / WARP_SIZE];
+                max_val_s  = selection_probs[i / WARP_SIZE];
                 max_expert = expert;
             }
         }

filename: tests/test-backend-ops.cpp
patch: @@ -8184,6 +8184,7 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
                     test_cases.emplace_back(new test_topk_moe({71, 22, 1, 1}, 8, with_norm, bias_probs, gate, scale_w));
                     test_cases.emplace_back(new test_topk_moe({128, 1, 1, 1}, 128, with_norm, bias_probs, gate, scale_w));
                     test_cases.emplace_back(new test_topk_moe({129, 1, 1, 1}, 128, with_norm, bias_probs, gate, scale_w));
+                    test_cases.emplace_back(new test_topk_moe({160, 4, 1, 1}, 160, with_norm, bias_probs, gate, scale_w));
                 }
             }
         }
Repository: huggingface/transformers
Pull request: fix prepare_config_and_inputs_for_common bug in llava test

@ydshieh, pls help review, thx very much.

Changed files:
filename: tests/models/llava/test_modeling_llava.py
patch: @@ -152,10 +152,11 @@ def prepare_config_and_inputs(self):
     def prepare_config_and_inputs_for_common(self):
         config_and_inputs = self.prepare_config_and_inputs()
         config, pixel_values = config_and_inputs
-        input_ids = ids_tensor([self.batch_size, self.seq_length], config.text_config.vocab_size - 1) + 1
+
+        input_ids = ids_tensor([self.batch_size, self.seq_length], config.text_config.vocab_size - 2) + 2
+        attention_mask = torch.ones(input_ids.shape, dtype=torch.long).to(torch_device)
         input_ids[input_ids == config.image_token_index] = self.pad_token_id
         input_ids[:, : self.num_image_tokens] = config.image_token_index
-        attention_mask = input_ids.ne(1).to(torch_device)
 
         inputs_dict = {
             "pixel_values": pixel_values,
Repository: ollama/ollama
Pull request: Limit GPU lib search for now

Fixes https://github.com/ollama/ollama/issues/4776

Changed files:
filename: gpu/gpu.go
patch: @@ -16,13 +16,12 @@ import (
 	"os"
 	"path/filepath"
 	"runtime"
-	"strconv"
 	"strings"
 	"sync"
 	"unsafe"
 
-	"github.com/ollama/ollama/format"
 	"github.com/ollama/ollama/envconfig"
+	"github.com/ollama/ollama/format"
 )
 
 type handles struct {
@@ -105,8 +104,6 @@ func initGPUHandles() *handles {
 	var cudartMgmtPatterns []string
 	var nvcudaMgmtName string
 	var nvcudaMgmtPatterns []string
-	var oneapiMgmtName string
-	var oneapiMgmtPatterns []string
 
 	tmpDir, _ := PayloadsDir()
 	switch runtime.GOOS {
@@ -118,8 +115,6 @@ func initGPUHandles() *handles {
 		// Aligned with driver, we can't carry as payloads
 		nvcudaMgmtName = "nvcuda.dll"
 		nvcudaMgmtPatterns = NvcudaWindowsGlobs
-		oneapiMgmtName = "ze_intel_gpu64.dll"
-		oneapiMgmtPatterns = OneapiWindowsGlobs
 	case "linux":
 		cudartMgmtName = "libcudart.so*"
 		if tmpDir != "" {
@@ -130,8 +125,6 @@ func initGPUHandles() *handles {
 		// Aligned with driver, we can't carry as payloads
 		nvcudaMgmtName = "libcuda.so*"
 		nvcudaMgmtPatterns = NvcudaLinuxGlobs
-		oneapiMgmtName = "libze_intel_gpu.so"
-		oneapiMgmtPatterns = OneapiLinuxGlobs
 	default:
 		return gpuHandles
 	}
@@ -159,17 +152,6 @@ func initGPUHandles() *handles {
 		}
 	}
 
-	oneapiLibPaths := FindGPULibs(oneapiMgmtName, oneapiMgmtPatterns)
-	if len(oneapiLibPaths) > 0 {
-		deviceCount, oneapi, libPath := LoadOneapiMgmt(oneapiLibPaths)
-		if oneapi != nil {
-			slog.Debug("detected Intel GPUs", "library", libPath, "count", deviceCount)
-			gpuHandles.oneapi = oneapi
-			gpuHandles.deviceCount = deviceCount
-			return gpuHandles
-		}
-	}
-
 	return gpuHandles
 }
 
@@ -245,18 +227,6 @@ func GetGPUInfo() GpuInfoList {
 			// TODO potentially sort on our own algorithm instead of what the underlying GPU library does...
 			resp = append(resp, gpuInfo)
 		}
-		if gpuHandles.oneapi != nil {
-			gpuInfo := GpuInfo{
-				Library: "oneapi",
-			}
-			C.oneapi_check_vram(*gpuHandles.oneapi, &memInfo)
-			var totalFreeMem float64 = float64(memInfo.free) * 0.95 // work-around: leave some reserve vram for mkl lib used in ggml-sycl backend.
-			memInfo.free = C.uint64_t(totalFreeMem)
-			gpuInfo.TotalMemory = uint64(memInfo.total)
-			gpuInfo.FreeMemory = uint64(memInfo.free)
-			gpuInfo.ID = strconv.Itoa(i)
-			resp = append(resp, gpuInfo)
-		}
 	}
 
 	// Then AMD
Repository: vercel/next.js
Pull request: guard navigation `use` hooks for React 18

We need to guard these calls, otherwise they fail in our React 18.3.1 tests. x-ref: https://github.com/vercel/next.js/actions/runs/18671327784/job/53236002824

Changed files:
filename: packages/next/src/client/components/navigation.ts
patch: @@ -1,6 +1,6 @@
 import type { Params } from '../../server/request/params'
 
-import { useContext, useMemo, use } from 'react'
+import React, { useContext, useMemo, use } from 'react'
 import {
   AppRouterContext,
   LayoutRouterContext,
@@ -72,7 +72,7 @@ export function useSearchParams(): ReadonlyURLSearchParams {
   }, [searchParams]) as ReadonlyURLSearchParams
 
   // Instrument with Suspense DevTools (dev-only)
-  if (process.env.NODE_ENV !== 'production') {
+  if (process.env.NODE_ENV !== 'production' && 'use' in React) {
     const navigationPromises = use(NavigationPromisesContext)
     if (navigationPromises) {
       return use(navigationPromises.searchParams)
@@ -108,7 +108,7 @@ export function usePathname(): string {
   const pathname = useContext(PathnameContext) as string
 
   // Instrument with Suspense DevTools (dev-only)
-  if (process.env.NODE_ENV !== 'production') {
+  if (process.env.NODE_ENV !== 'production' && 'use' in React) {
     const navigationPromises = use(NavigationPromisesContext)
     if (navigationPromises) {
       return use(navigationPromises.pathname)
@@ -176,7 +176,7 @@ export function useParams<T extends Params = Params>(): T {
   const params = useContext(PathParamsContext) as T
 
   // Instrument with Suspense DevTools (dev-only)
-  if (process.env.NODE_ENV !== 'production') {
+  if (process.env.NODE_ENV !== 'production' && 'use' in React) {
     const navigationPromises = use(NavigationPromisesContext)
     if (navigationPromises) {
       return use(navigationPromises.params) as T
@@ -222,7 +222,7 @@ export function useSelectedLayoutSegments(
   if (!context) return null
 
   // Instrument with Suspense DevTools (dev-only)
-  if (process.env.NODE_ENV !== 'production') {
+  if (process.env.NODE_ENV !== 'production' && 'use' in React) {
     const navigationPromises = use(NavigationPromisesContext)
     if (navigationPromises) {
       const promise =
@@ -265,7 +265,11 @@ export function useSelectedLayoutSegment(
   const selectedLayoutSegments = useSelectedLayoutSegments(parallelRouteKey)
 
   // Instrument with Suspense DevTools (dev-only)
-  if (process.env.NODE_ENV !== 'production' && navigationPromises) {
+  if (
+    process.env.NODE_ENV !== 'production' &&
+    navigationPromises &&
+    'use' in React
+  ) {
     const promise =
       navigationPromises.selectedLayoutSegmentPromises?.get(parallelRouteKey)
     if (promise) {
Repository: huggingface/transformers
Pull request: Fix typo in image_processing_lfm2_vl_fast

# What does this PR do?
Fix small typo. Without consequences, but still confusing.

Fixes https://github.com/huggingface/transformers/issues/41919

Changed files:
filename: src/transformers/models/lfm2_vl/image_processing_lfm2_vl_fast.py
patch: @@ -209,8 +209,8 @@ class Lfm2VlImageProcessorFast(BaseImageProcessorFast):
     do_normalize = True
     do_pad = True
     return_row_col_info = False
-    image_mean = IMAGENET_STANDARD_STD
-    image_std = IMAGENET_STANDARD_MEAN
+    image_mean = IMAGENET_STANDARD_MEAN
+    image_std = IMAGENET_STANDARD_STD
     valid_kwargs = Lfm2VlImageProcessorKwargs
     model_input_names = ["pixel_values", "pixel_attention_mask", "spatial_shapes"]
Repository: ollama/ollama
Pull request: added IsValidNamespace function

added function to the package for purpose of validating new usernames on the website

Changed files:
filename: types/model/name.go
patch: @@ -251,6 +251,10 @@ func (n Name) DisplayShortest() string {
 	return sb.String()
 }
 
+func IsValidNamespace(namespace string) bool {
+	return isValidPart(kindNamespace, namespace)
+}
+
 // IsValid reports whether all parts of the name are present and valid. The
 // digest is a special case, and is checked for validity only if present.
 func (n Name) IsValid() bool {

filename: types/model/name_test.go
patch: @@ -385,3 +385,30 @@ func FuzzName(f *testing.F) {
 
 	})
 }
+
+func TestIsValidNamespace(t *testing.T) {
+	cases := []struct {
+		username   string
+		expected   bool
+	}{
+		{"", false},
+		{"a", true},
+		{"a:b", false},
+		{"a/b", false},
+		{"a:b/c", false},
+		{"a/b:c", false},
+		{"a/b:c", false},
+		{"a/b:c/d", false},
+		{"a/b:c/d@e", false},
+		{"a/b:c/d@sha256-100", false},
+		{"himynameisjoe", true},
+		{"himynameisreallyreallyreallyreallylongbutitshouldstillbevalid", true},
+	}
+	for _, tt := range cases {
+		t.Run(tt.username, func(t *testing.T) {
+			if got := IsValidNamespace(tt.username); got != tt.expected {
+				t.Errorf("IsValidName(%q) = %v; want %v", tt.username, got, tt.expected)
+			}
+		})
+	}
+}
Repository: facebook/react
Pull request: [prettier] Ignore compiler/target


Add missing directory to prettierignore.
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31168).
* #31167
* #31166
* #31165
* #31164
* #31148
* __->__ #31168

Changed files:
filename: .prettierignore
patch: @@ -24,6 +24,7 @@ compiler/**/.next
 compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-kitchensink.js
 
 compiler/crates
+compiler/target
 compiler/apps/playground/public
 
 compiler/**/LICENSE
Repository: vercel/next.js
Pull request: [turbopack] Don't warn on the lightning css experimental option

This is ignored by turbopack but we also always run with useLightningCss so it isn't harmful to set this.  If people are using both webpack and turbopack then setting this is reasonable.

Closes PACK-5727

Changed files:
filename: packages/next/src/lib/turbopack-warning.ts
patch: @@ -40,9 +40,6 @@ const unsupportedTurbopackNextConfigOptions = [
   'experimental.fullySpecified',
   'experimental.urlImports',
   'experimental.slowModuleDetection',
-
-  // We always use lightningcss
-  'experimental.useLightningcss',
 ]
 
 /**  */
Repository: denoland/deno
Pull request: fix(ext/node): add Symbol.dispose and Symbol.asyncDispose to fs.Dir

Closes #32966

Adds `Symbol.dispose` and `Symbol.asyncDispose` to the `Dir` class in `ext/node/polyfills/_fs/_fs_dir.ts`, so that `using` and `await using` work with `fs.Dir` objects.

- `[Symbol.dispose]()` delegates to `closeSync()` (no-op in Deno, mirrors Node behavior)
- `[Symbol.asyncDispose]()` delegates to `close()` (returns `Promise<void>`)

`FileHandle` already implements `[Symbol.asyncDispose]` and required no change.

---

Note: This PR was written with AI assistance (Claude).

Changed files:
filename: ext/node/polyfills/_fs/_fs_dir.ts
patch: @@ -15,6 +15,8 @@ const {
   Uint8ArrayPrototype,
   PromisePrototypeThen,
   SymbolAsyncIterator,
+  SymbolAsyncDispose,
+  SymbolDispose,
   ArrayIteratorPrototypeNext,
   AsyncGeneratorPrototypeNext,
   SymbolIterator,
@@ -110,6 +112,14 @@ export default class Dir {
     //No op
   }
 
+  [SymbolDispose]() {
+    this.closeSync();
+  }
+
+  [SymbolAsyncDispose](): Promise<void> {
+    return this.close();
+  }
+
   async *[SymbolAsyncIterator](): AsyncIterableIterator<Dirent> {
     try {
       while (true) {

filename: tests/unit_node/fs_test.ts
patch: @@ -44,6 +44,7 @@ import {
   lstatSync,
   mkdtempSync,
   openAsBlob,
+  opendirSync,
   openSync,
   promises,
   promises as fsPromises,
@@ -1738,3 +1739,21 @@ Deno.test({
     );
   },
 });
+
+Deno.test(
+  "[node/fs Dir] Dir is disposable via Symbol.dispose",
+  { permissions: { read: true } },
+  () => {
+    using dir = opendirSync(".");
+    void dir;
+  },
+);
+
+Deno.test(
+  "[node/fs Dir] Dir is async-disposable via Symbol.asyncDispose",
+  { permissions: { read: true } },
+  async () => {
+    await using dir = await fsPromises.opendir(".");
+    void dir;
+  },
+);
Repository: ggml-org/llama.cpp
Pull request: Clarify that steps also apply to linux

Added note that the windows PowerShell commands in the file work on Linux as well.


Changed files:
filename: docs/backend/OPENCL.md
patch: @@ -218,6 +218,56 @@ cmake .. -G Ninja `
 ninja
 ```
 
+## Linux
+
+The two steps just above also apply to Linux. When building for linux, the commands are mostly the same as those for PowerShell on Windows, but in the second step they do not have the `-DCMAKE_TOOLCHAIN_FILE` parameter, and then in both steps the backticks are replaced with back slashes.
+
+If not installed already, install Git, CMake, Clang, Ninja and Python, then run in the terminal the following:
+
+### I. Setup Environment
+
+1. **Install OpenCL Headers and Library**
+
+```bash
+mkdir -p ~/dev/llm
+
+cd ~/dev/llm
+git clone https://github.com/KhronosGroup/OpenCL-Headers && cd OpenCL-Headers
+mkdir build && cd build
+cmake .. -G Ninja \
+  -DBUILD_TESTING=OFF \
+  -DOPENCL_HEADERS_BUILD_TESTING=OFF \
+  -DOPENCL_HEADERS_BUILD_CXX_TESTS=OFF \
+  -DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
+cmake --build . --target install
+
+cd ~/dev/llm
+git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader && cd OpenCL-ICD-Loader
+mkdir build && cd build
+cmake .. -G Ninja \
+  -DCMAKE_BUILD_TYPE=Release \
+  -DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" \
+  -DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
+cmake --build . --target install
+```
+
+### II. Build llama.cpp
+
+```bash
+mkdir -p ~/dev/llm
+cd ~/dev/llm
+
+git clone https://github.com/ggml-org/llama.cpp && cd llama.cpp
+mkdir build && cd build
+
+cmake .. -G Ninja \
+  -DCMAKE_BUILD_TYPE=Release \
+  -DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" \
+  -DBUILD_SHARED_LIBS=OFF \
+  -DGGML_OPENCL=ON
+ninja
+```
+
 ## Known Issues
 
 - Flash attention does not always improve performance.
Repository: ollama/ollama
Pull request: use `int32_t` for call to tokenize


Changed files:
filename: llm/llm.go
patch: @@ -63,12 +63,27 @@ func (llm *llamaModel) Tokenize(s string) []int {
 	cs := C.CString(s)
 	defer C.free(unsafe.Pointer(cs))
 
-	tokens := make([]int, len(s)+2)
-	if n := C.llama_tokenize(llm.m, cs, C.int(len(s)), (*C.llama_token)(unsafe.Pointer(&tokens[0])), C.int(len(s)+2), false, true); n > 0 {
-		return tokens[:n]
+	ltokens := make([]C.llama_token, len(s)+2)
+	n := C.llama_tokenize(
+		llm.m,
+		cs,
+		C.int32_t(len(s)),
+		&ltokens[0],
+		C.int32_t(len(ltokens)),
+		false,
+		true,
+	)
+
+	if n < 0 {
+		return nil
 	}
 
-	return nil
+	tokens := make([]int, n)
+	for i := 0; i < int(n); i++ {
+		tokens[i] = int(ltokens[i])
+	}
+
+	return tokens
 }
 
 func (llm *llamaModel) Detokenize(i32s []int) string {