Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add a bitmask for the ml runtime version

laurenspriem50345866ba12
diff --git a/mobile/apps/photos/lib/models/ml/ml_versions.dart b/mobile/apps/photos/lib/models/ml/ml_versions.dart
index 35cd51b769..fc13e000ee 100644
--- a/mobile/apps/photos/lib/models/ml/ml_versions.dart
+++ b/mobile/apps/photos/lib/models/ml/ml_versions.dart
@@ -6,6 +6,10 @@ const clusterMlVersion = 1;
const petMlVersion = 1;
const minimumClusterSize = 2;
+/// Bits for the `flags` bitmask on RemoteFaceEmbedding / RemoteClipEmbedding.
+/// Once shipped, a bit's meaning is immutable β€” only add new bits.
+const int mlIndexFlagRuntimeRust = 1 << 0;
+
const embeddingFetchLimit = 200;
final fileDownloadMlLimit = Platform.isIOS ? 5 : 10;
const maxFileDownloadSize = 100000000;
diff --git a/mobile/apps/photos/lib/services/filedata/model/file_data.dart b/mobile/apps/photos/lib/services/filedata/model/file_data.dart
index 904b12623f..ab45804713 100644
--- a/mobile/apps/photos/lib/services/filedata/model/file_data.dart
+++ b/mobile/apps/photos/lib/services/filedata/model/file_data.dart
@@ -101,12 +101,18 @@ class RemoteFaceEmbedding {
final int height;
final int width;
+ /// Bitmask describing properties of this index (e.g. which runtime produced
+ /// it). Bits are defined in `ml_versions.dart`. Absent on the wire => 0
+ /// (legacy).
+ final int flags;
+
RemoteFaceEmbedding(
this.faces,
this.version, {
required this.client,
required this.height,
required this.width,
+ this.flags = 0,
});
// toJson
@@ -116,6 +122,7 @@ class RemoteFaceEmbedding {
'client': client,
'height': height,
'width': width,
+ if (flags != 0) 'flags': flags,
};
// fromJson
@@ -128,6 +135,7 @@ class RemoteFaceEmbedding {
client: json['client'] as String,
height: json['height'] as int,
width: json['width'] as int,
+ flags: (json['flags'] as int?) ?? 0,
);
}
}
@@ -137,10 +145,16 @@ class RemoteClipEmbedding {
final String client;
final List<double> embedding;
+ /// Bitmask describing properties of this index (e.g. which runtime produced
+ /// it). Bits are defined in `ml_versions.dart`. Absent on the wire => 0
+ /// (legacy).
+ final int flags;
+
RemoteClipEmbedding(
this.embedding, {
required this.version,
required this.client,
+ this.flags = 0,
});
// toJson
@@ -148,6 +162,7 @@ class RemoteClipEmbedding {
'embedding': embedding,
'version': version,
'client': client,
+ if (flags != 0) 'flags': flags,
};
// fromJson
@@ -156,6 +171,7 @@ class RemoteClipEmbedding {
parseAsDoubleList(json['embedding'] as List),
version: json['version'] as int,
client: json['client'] as String,
+ flags: (json['flags'] as int?) ?? 0,
);
}
}
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart b/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart
index 3f6c142d81..815ec538ed 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart
@@ -103,6 +103,7 @@ class MLIndexingIsolate extends SuperIsolate {
return null;
}
result = MLResult.fromJsonString(resultJsonString);
+ result.usedRustMl = useRustMl;
} catch (e, s) {
if (isExpectedMlSkipError(e)) {
rethrow;
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_result.dart b/mobile/apps/photos/lib/services/machine_learning/ml_result.dart
index 38e121022a..a231b0effc 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_result.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_result.dart
@@ -17,6 +17,10 @@ class MLResult {
Dimensions decodedImageSize;
+ /// Which runtime actually produced this result. Stamped by the caller of
+ /// the indexing isolate; not serialized to/from the isolate JSON payload.
+ bool usedRustMl = false;
+
bool get ranML => facesRan || clipRan || petsRan;
bool get facesRan => faces != null;
bool get clipRan => clip != null;
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
index 6c551c5c13..c409eadda1 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
@@ -741,6 +741,10 @@ class MLService {
actuallyRanML = result.ranML;
if (!actuallyRanML) return actuallyRanML;
final bool isOffline = instruction.isOffline;
+ // Bitmask describing properties of this index (e.g. which runtime
+ // produced it), so remote indexes stay distinguishable between rust
+ // and legacy during and after the rust ML rollout.
+ final int remoteFlags = result.usedRustMl ? mlIndexFlagRuntimeRust : 0;
// Prepare storing data on remote (online mode only)
final FileDataEntity? dataEntity = isOffline
? null
@@ -774,6 +778,7 @@ class MLService {
client: client,
height: result.decodedImageSize.height,
width: result.decodedImageSize.width,
+ flags: remoteFlags,
),
);
}
@@ -786,6 +791,7 @@ class MLService {
result.clip!.embedding,
version: clipMlVersion,
client: client,
+ flags: remoteFlags,
),
);
}