-
-
Notifications
You must be signed in to change notification settings - Fork 230
fix(threads): remove runaway nThreads migration and show resolved Au… #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import { useState, useEffect } from 'react'; | ||
| import { Platform } from 'react-native'; | ||
| import { useAppStore } from '../stores'; | ||
| import { CacheType, INFERENCE_BACKENDS } from '../types'; | ||
| import { hardwareService } from '../services/hardware'; | ||
|
|
||
| /** Feature flag: Set to true to enable HTP/Hexagon NPU support. Currently disabled. */ | ||
| const HTP_ENABLED = false; | ||
|
|
@@ -31,8 +33,17 @@ | |
| // OpenCL and HTP force f16 in the native loader, so lock the UI to match. | ||
| const cacheDisabled = gpuForcesF16; | ||
| const displayCacheType = cacheDisabled ? 'f16' : currentCacheType; | ||
| const [resolvedThreadCount, setResolvedThreadCount] = useState<number | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (settings?.nThreads !== 0) return; | ||
| hardwareService.getRecommendedThreadCount().then(setResolvedThreadCount); | ||
| }, [settings?.nThreads]); | ||
|
Comment on lines
+36
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize the state with the cached value and update the cache once the recommended thread count is resolved. To prevent state updates on unmounted components or race conditions from stale renders, use a cancellation flag within the useEffect as per repository guidelines. The cache update itself can remain 'fire-and-forget' to ensure the value is available for future mounts even if the current one is cancelled. const [resolvedThreadCount, setResolvedThreadCount] = useState<number | null>(cachedRecommendedThreads);
useEffect(() => {
let isCancelled = false;
if (settings?.nThreads !== 0 || resolvedThreadCount !== null) return;
hardwareService.getRecommendedThreadCount().then(count => {
cachedRecommendedThreads = count;
if (isCancelled) return;
setResolvedThreadCount(count);
});
return () => {
isCancelled = true;
};
}, [settings?.nThreads, resolvedThreadCount]);References
|
||
|
|
||
| const cpuThreadsSliderValue = settings?.nThreads && settings.nThreads > 0 ? settings.nThreads : 1; | ||
| const cpuThreadsDisplayValue = settings?.nThreads === 0 ? 'Auto' : String(settings?.nThreads ?? 6); | ||
| const cpuThreadsDisplayValue = settings?.nThreads === 0 | ||
| ? (resolvedThreadCount != null ? `Auto (${resolvedThreadCount})` : 'Auto') | ||
|
Check warning on line 45 in src/hooks/useTextGenerationAdvanced.ts
|
||
| : String(cpuThreadsSliderValue); | ||
|
|
||
| const handleFlashAttnToggle = (flashAttn: boolean) => { | ||
| if (!flashAttn && isQuantizedCache) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid a visible flicker from "Auto" to "Auto (N)" on every mount of the settings screen, and to prevent redundant asynchronous calls to fetch the hardware core count (which is static for the device), consider caching the resolved thread count in a module-level variable.