Skip to content

Commit

Permalink
fix: unable to use AiService on arm64 (#15261)
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 authored Jan 14, 2025
1 parent b161601 commit 6820878
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 @@ -36,6 +36,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 @@ -15,7 +15,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 @@ -31,8 +31,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 @@ -64,6 +63,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 6820878

Please sign in to comment.