Skip to content

Commit 1cd6018

Browse files
committed
add sign
1 parent 55b6590 commit 1cd6018

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

CodeApp/Services/ANEInferenceEngine.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,19 @@ class ANEInferenceEngine {
202202
// Group RMSNorm
203203
y = groupRMSNorm(y, weight: w.ssmNorm)
204204

205-
// Gate
205+
// D skip connection (feedthrough: y += D * x)
206+
let D = w.ssmBeta.matvec(xNorm)
207+
for g in 0..<nGroups {
208+
for j in 0..<dInnerPerGroup {
209+
let ch = g * dInnerPerGroup + j
210+
y[ch] += D[g] * xSsm[ch]
211+
}
212+
}
213+
214+
// Gate (SiLU, NOT sigmoid)
206215
let gateRaw = w.attnGate.matvec(xNorm)
207216
for i in 0..<ssmInner {
208-
y[i] *= 1.0 / (1.0 + exp(-gateRaw[i]))
217+
y[i] *= gateRaw[i] / (1.0 + exp(-gateRaw[i]))
209218
}
210219

211220
// Output projection + residual
@@ -431,14 +440,16 @@ class ANEInferenceEngine {
431440
}
432441

433442
private func groupRMSNorm(_ x: [Float], weight: [Float]) -> [Float] {
443+
let perChannel = weight.count > dInnerPerGroup
434444
var result = x
435445
for g in 0..<nGroups {
436446
let off = g * dInnerPerGroup
437447
var sumSq: Float = 0
438448
for j in 0..<dInnerPerGroup { sumSq += result[off + j] * result[off + j] }
439449
let rms = sqrt(sumSq / Float(dInnerPerGroup) + rmsEps)
440450
for j in 0..<dInnerPerGroup {
441-
result[off + j] = (result[off + j] / rms) * weight[j]
451+
let wIdx = perChannel ? (off + j) : j
452+
result[off + j] = (result[off + j] / rms) * weight[wIdx]
442453
}
443454
}
444455
return result

fastlane/Fastfile

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,17 @@ platform :ios do
159159
UI.important("Warning: Could not find main provisioning profile '#{main_profile}'")
160160
end
161161

162-
# Re-sign embedded frameworks
162+
# Extract entitlements from the already-signed app in the archive
163+
# (codesign -d --entitlements extracts the embedded entitlements)
164+
main_entitlements_file = File.join(export_path, "main.entitlements.plist")
165+
sh("codesign -d --entitlements '#{main_entitlements_file}' '#{exported_app}' 2>/dev/null || true")
166+
has_main_entitlements = File.exist?(main_entitlements_file) && File.size(main_entitlements_file) > 0
167+
168+
# Re-sign embedded frameworks (no entitlements needed for frameworks)
163169
frameworks_path = File.join(exported_app, "Frameworks")
164170
if File.directory?(frameworks_path)
165171
Dir["#{frameworks_path}/*.framework", "#{frameworks_path}/*.dylib"].each do |fw|
166-
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --timestamp=none '#{fw}'")
172+
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --timestamp '#{fw}'")
167173
end
168174
end
169175

@@ -176,23 +182,24 @@ platform :ios do
176182
appex_fw = File.join(appex, "Frameworks")
177183
if File.directory?(appex_fw)
178184
Dir["#{appex_fw}/*.framework", "#{appex_fw}/*.dylib"].each do |fw|
179-
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --timestamp=none '#{fw}'")
185+
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --timestamp '#{fw}'")
180186
end
181187
end
182-
entitlements_appex = File.join(appex, "archived-expanded-entitlements.xcent")
183-
if File.exist?(entitlements_appex)
184-
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --entitlements '#{entitlements_appex}' --timestamp=none '#{appex}'")
188+
# Extract extension entitlements from existing signature
189+
ext_entitlements_file = File.join(export_path, "ext_#{File.basename(appex)}.entitlements.plist")
190+
sh("codesign -d --entitlements '#{ext_entitlements_file}' '#{appex}' 2>/dev/null || true")
191+
if File.exist?(ext_entitlements_file) && File.size(ext_entitlements_file) > 0
192+
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --entitlements '#{ext_entitlements_file}' --timestamp '#{appex}'")
185193
else
186-
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --timestamp=none '#{appex}'")
194+
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --timestamp '#{appex}'")
187195
end
188196
end
189197

190198
# Re-sign the main app bundle
191-
entitlements_main = File.join(exported_app, "archived-expanded-entitlements.xcent")
192-
if File.exist?(entitlements_main)
193-
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --entitlements '#{entitlements_main}' --timestamp=none '#{exported_app}'")
199+
if has_main_entitlements
200+
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --entitlements '#{main_entitlements_file}' --timestamp '#{exported_app}'")
194201
else
195-
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --timestamp=none '#{exported_app}'")
202+
sh("codesign --force --sign '#{sign_identity}' --keychain '#{keychain_path}' --timestamp '#{exported_app}'")
196203
end
197204

198205
ipa_output = File.join(export_path, "Code.ipa")

0 commit comments

Comments
 (0)