Skip to content

Commit

Permalink
fix: unable to use AiService on arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Jan 12, 2025
1 parent f8e3db9 commit c25078a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- Fix: disableClustering設定時の初期化ロジックを調整( #15223 )
- Fix: ActivityPubリクエストかどうかの判定が正しくない問題を修正
(Cherry-picked from https://github.com/MisskeyIO/misskey/pull/869)
- Fix: AIセンシティブ判定が arm64 環境で動作しない問題を修正

## 2024.11.0

Expand Down
21 changes: 18 additions & 3 deletions packages/backend/src/core/AiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { bindThis } from '@/decorators.js';
const _filename = fileURLToPath(import.meta.url);
const _dirname = dirname(_filename);

const REQUIRED_CPU_FLAGS = ['avx2', 'fma'];
const REQUIRED_CPU_FLAGS_X64 = ['avx2', 'fma'];
let isSupportedCpu: undefined | boolean = undefined;

@Injectable()
Expand All @@ -32,8 +32,7 @@ export class AiService {
public async detectSensitive(path: string): Promise<nsfw.PredictionType[] | null> {
try {
if (isSupportedCpu === undefined) {
const cpuFlags = await this.getCpuFlags();
isSupportedCpu = REQUIRED_CPU_FLAGS.every(required => cpuFlags.includes(required));
isSupportedCpu = await this.computeIsSupportedCpu();
}

if (!isSupportedCpu) {
Expand Down Expand Up @@ -66,6 +65,22 @@ export class AiService {
}
}

private async computeIsSupportedCpu(): Promise<boolean> {
switch (process.arch) {
case 'x64': {
const cpuFlags = await this.getCpuFlags();
return REQUIRED_CPU_FLAGS_X64.every(required => cpuFlags.includes(required));
}
case 'arm64': {
// As far as I know, no required CPU flags for ARM64.
return true;
}
default: {
return false;
}
}
}

@bindThis
private async getCpuFlags(): Promise<string[]> {
const str = await si.cpuFlags();
Expand Down

0 comments on commit c25078a

Please sign in to comment.