Skip to content

Commit

Permalink
[Feat] sync llama.cpp (#151)
Browse files Browse the repository at this point in the history
* feat: allow custom benchs to be shared

* feat: bench: limit max pp to n_ubatch

* feat: sync llama.rn -> llama.cpp

* feat: remove penalize_nl
  • Loading branch information
a-ghorbani authored Dec 28, 2024
1 parent b836d07 commit 62c9126
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 220 deletions.
136 changes: 68 additions & 68 deletions ios/PocketPal.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
use_frameworks! :linkage => linkage.to_sym
else
# Configure CocoaPods to use static frameworks required for Firebase.
# Firebase is used exclusively for sending benchmarks (with user consent) to Hugging Face Spaces.
# Firebase enables App Check functionality, ensuring unauthenticated users can securely submit their benchmark data.
use_frameworks! :linkage => :static
end

# Enable Firebase as a static framework
Expand All @@ -38,6 +33,13 @@ target 'PocketPal' do
# Pods for testing
end

# Firebase (App Check)
pod 'Firebase', :modular_headers => true
pod 'FirebaseCore', :modular_headers => true
pod 'FirebaseAppCheck', :modular_headers => true
pod 'GoogleUtilities', :modular_headers => true


post_install do |installer|
# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
react_native_post_install(
Expand All @@ -48,8 +50,5 @@ target 'PocketPal' do
)
end

# Firebase (App Check)
pod 'Firebase', :modular_headers => true
pod 'FirebaseCore', :modular_headers => true
pod 'FirebaseAppCheck', :modular_headers => true

end
104 changes: 59 additions & 45 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ PODS:
- GoogleUtilities/Network (~> 8.0)
- "GoogleUtilities/NSData+zlib (~> 8.0)"
- nanopb (~> 3.30910.0)
- GoogleUtilities (8.0.2):
- GoogleUtilities/AppDelegateSwizzler (= 8.0.2)
- GoogleUtilities/Environment (= 8.0.2)
- GoogleUtilities/Logger (= 8.0.2)
- GoogleUtilities/MethodSwizzler (= 8.0.2)
- GoogleUtilities/Network (= 8.0.2)
- "GoogleUtilities/NSData+zlib (= 8.0.2)"
- GoogleUtilities/Privacy (= 8.0.2)
- GoogleUtilities/Reachability (= 8.0.2)
- GoogleUtilities/SwizzlerTestHelpers (= 8.0.2)
- GoogleUtilities/UserDefaults (= 8.0.2)
- GoogleUtilities/AppDelegateSwizzler (8.0.2):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
Expand All @@ -121,13 +132,15 @@ PODS:
- GoogleUtilities/Reachability (8.0.2):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- GoogleUtilities/SwizzlerTestHelpers (8.0.2):
- GoogleUtilities/MethodSwizzler
- GoogleUtilities/UserDefaults (8.0.2):
- GoogleUtilities/Logger
- GoogleUtilities/Privacy
- hermes-engine (0.76.3):
- hermes-engine/Pre-built (= 0.76.3)
- hermes-engine/Pre-built (0.76.3)
- llama-rn (0.4.3-1):
- llama-rn (0.4.7-2):
- React-Core
- nanopb (3.30910.0):
- nanopb/decode (= 3.30910.0)
Expand Down Expand Up @@ -1934,6 +1947,7 @@ DEPENDENCIES:
- FirebaseCore
- fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`)
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
- GoogleUtilities
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
- "llama-rn (from `../node_modules/@pocketpalai/llama.rn`)"
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
Expand Down Expand Up @@ -2212,7 +2226,7 @@ SPEC CHECKSUMS:
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
BVLinearGradient: cb006ba232a1f3e4f341bb62c42d1098c284da70
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
dr-pogodin-react-native-fs: 6472f94270d0a5720221bd0ffa377dad303f6e29
dr-pogodin-react-native-fs: 6c198fc213e6a8d6679885d4df5868feed77db78
FBLazyVector: be7314029d6ec6b90f0f75ce1195b8130ed9ac4f
Firebase: 7a56fe4f56b5ab81b86a6822f5b8f909ae6fc7e2
FirebaseAnalytics: 2f4a11eeb7a0e9c6fcf642d4e6aaca7fa4d38c28
Expand All @@ -2226,7 +2240,7 @@ SPEC CHECKSUMS:
GoogleAppMeasurement: ee5c2d2242816773fbf79e5b0563f5355ef1c315
GoogleUtilities: 26a3abef001b6533cf678d3eb38fd3f614b7872d
hermes-engine: 0555a84ea495e8e3b4bde71b597cd87fbb382888
llama-rn: 740c802dbb28961bf4a94e658963bc22d81150a7
llama-rn: 07deb682d25cca8050d69323c05c284d2de1e88a
nanopb: fad817b59e0457d11a5dfbde799381cd727c1275
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47
RCT-Folly: 84578c8756030547307e4572ab1947de1685c599
Expand All @@ -2238,76 +2252,76 @@ SPEC CHECKSUMS:
React-Core: 14708d0ebf0f961647347a7ae9cebcfaa75c99aa
React-CoreModules: 42b62e50cb4ac9a8ca92b48b263355cebcc1a523
React-cxxreact: 846f1d9eb37a3dec19738d195d313deb7e9ee36b
React-debug: ccf1390c0984edf6f9601eb3b13383d54beb6348
React-defaultsnativemodule: 808ea6f3dc257a6ffa3e1dbf214be4d12e56066a
React-domnativemodule: f76fdf0da6c0504fa70341a6a4e65447241c1561
React-Fabric: ed269fc1b32f4bc15bb171083465e0ccfa38d7cd
React-FabricComponents: 20e59d87b3ed9960c26792fb7d3226dbb9831f77
React-FabricImage: 3d179c86131f5ea09a00a6b9344919233e8139e5
React-featureflags: ad8c56c9dd770ea485bd4f564af2878dd77ed623
React-featureflagsnativemodule: 197f04601054c8c23940405ceb9c9ae07bf53d55
React-graphics: 845d105c042837f6eb7fb806cf16e95901191884
React-debug: 931ca94abd6b1bcab539e356e20df788afecae8f
React-defaultsnativemodule: 6f56c95a8cd7b7fcfa6f983b19270753000c1a4e
React-domnativemodule: 42711869923d77713e8d090f489580c330ff2033
React-Fabric: 2709bcae28c5b567337b3bad4ec1aa8b81aa1241
React-FabricComponents: f35e150acf873109d244bd8c4535425d51f26672
React-FabricImage: 6dd7af0496dae7924553f8b3cd2b134d86256a48
React-featureflags: 7c7a74b65ee5a228f520b387ebfe0e8d9cecc622
React-featureflagsnativemodule: 2e98d69110ccee1cf10acafad34041940457545c
React-graphics: ba13cb82b71ec2e0ad9dac2ae31867b5656d5a28
React-hermes: 4bfb5c90304c4d2aa36b3404ddd00df591dcae8a
React-idlecallbacksnativemodule: cb04ed83ee5e70bb2c5e342d8538f4c31001af01
React-ImageManager: 4e2ead3d25b77d08e48f3c263884e8a549ce0528
React-jserrorhandler: 6576ec21bce9547fd91fa838593c2339cd448cc0
React-idlecallbacksnativemodule: 4a77976e6b6d74ebe2008ade2e46c69484a69f45
React-ImageManager: 0464b2fac74d9d06d44abc3e85035424fc0d1a70
React-jserrorhandler: 4c8ee0547d89d1bfe9cd740ca83d229934cc94e4
React-jsi: 927e83b5aef299ca42842cd1ad696c4cf301d5eb
React-jsiexecutor: ba6b1fbaa388a99fcfb750529fed3ce65efbda4f
React-jsinspector: 1538d8147957b2ac38fcb0e0cc3fd3ea7d7ef179
React-jsitracing: f61ecea3cf2e5a08a30274fa9fdf29fd637de7f3
React-jsinspector: 1f9f161bf0961df50d2843802a431eb4fd4059cf
React-jsitracing: f6f65398e2d58bd24523ba210b277681e9cf2ee0
React-logger: 2736a90a3fdaed3dab1e2e9c5a5e9b3be00c287d
React-Mapbuffer: 12bbf447b326f0de8a472998eceafbdc4f43ca4e
React-microtasksnativemodule: 2841fe62a6d2fdfdd1051286394186fd1d210f99
react-native-blur: aeda95624971b20d19c6c0fb291c411056e6d270
React-Mapbuffer: bd6a2ffbf401f11cfc8b5e8f38acab9fe117620c
React-microtasksnativemodule: e3e161b03573a22cf4e05434fe5309c7847ef197
react-native-blur: 3d5dd1ed2dd810b304ac3bcee9cf7d460757c89b
react-native-config: ea75335a7cca1d3326de1da384227e580a7c082e
react-native-document-picker: 302837be22e5e557340d1d510bddb1c658bd4475
react-native-document-picker: 530879d9e89b490f0954bcc4ab697c5b5e35d659
react-native-get-random-values: d16467cf726c618e9c7a8c3c39c31faa2244bbba
react-native-render-html: 5afc4751f1a98621b3009432ef84c47019dcb2bd
react-native-safe-area-context: b13be9714d9771fbde0120bc519c963484de3a71
react-native-slider: 6750dca1fcfa1403dc1b4841f3f8c87c2d19f054
React-nativeconfig: f2bddc1e6c2eb793c065b37e12c513fdea88afef
React-NativeModulesApple: 43be3b84598af78efe8fcdbad90033caef83af43
react-native-slider: fc7f35c082abec47e341dfe43657a1c26f38db2f
React-nativeconfig: aeed6e2a8ac02b2df54476afcc7c663416c12bf7
React-NativeModulesApple: c0783e5e21c71aa2764ac33120abc96208466fa6
React-perflogger: 2991d4258277af250eb7a2705980ebb3ef9ba85e
React-performancetimeline: d81ada298f4246ed1e093d1bfd989be707a34902
React-performancetimeline: 76a55d0be7293adfce8603eafb8dbae92234352d
React-RCTActionSheet: c940a35d71686941ac2b96dd07bde11ea0f0c34f
React-RCTAnimation: db10ffa5b463794089b5319818f1df1e0b996422
React-RCTAppDelegate: c398e067ecde4909eab8b48adf06bf03783cd335
React-RCTBlob: 2ede907cfc8039c5f5da32b3ba9e144b663c3c98
React-RCTFabric: dcb63d1d85cf6c66e85a3b827a71129de5a3dbc1
React-RCTFabric: 9612452b193ce3daa3a05fdbeba4ffea756b17f8
React-RCTImage: 3d6b5cc404c62d2b2cd767061a56bd48b4300f5e
React-RCTLinking: 548cf5c3fe935f3d0c8df5dc3c234283df48cea6
React-RCTNetwork: 59f683fee79f9187b8ee4c270343b474ad37b42c
React-RCTSettings: b14bd94b2ac87c803375a0873746ef31c7b0eead
React-RCTText: 24e7a9b64341d6a1c98e1eabc5471b88c8bc61f1
React-RCTVibration: 2830b19dca45d23dc61b3c93c25fbc7b85979202
React-rendererconsistency: 678c479227d4be6b97a5cebeb891f0af66481b44
React-rendererdebug: 73a2e636671885c26518088d7ff0e49c729270af
React-rncore: 2087c670978028c09b87e767a95a91997ddb00ab
React-RuntimeApple: ed413531c98c3437ec0d7eff82b1d8ef5f4da60e
React-RuntimeCore: 783c8e32a5281091675ac6eecbfc09b993accb77
React-rendererconsistency: 52b471890a1946991f2db81aa6867b14d93f4ea5
React-rendererdebug: c2496eb27c25d367b7e80a8a4a1babc21b6cc64b
React-rncore: 33ea67bfd2eeaa4f4a0c9e0e8bd55e9b7ccb9faa
React-RuntimeApple: 28bcdbce4517b9428ab127d42d7b6bfeb27eb69c
React-RuntimeCore: d629b37225984a26c57803d857c8357c839f3fef
React-runtimeexecutor: db3f17084ee7b71ab84912c527d428cc3a137841
React-RuntimeHermes: 58b31fa6f2aea69fb1c0657320aca09a9eb87678
React-runtimescheduler: a3cfaf71458952e2a9e8854cd6c79a6dc1ebe25e
React-timing: 854b47632fdd9f7d2690ea6444d01b7071d5da69
React-utils: 5bb4b8442d3f1d068e84a9d7afdb6130035fff2f
ReactCodegen: b91032e6eb7dc1019852a3c4fe366e730299b68d
ReactCommon: 49e601e49039dc5795658db8c407b87152a6b401
React-RuntimeHermes: 5d857268954776a1c6f0e0ecff1f7860806bb43b
React-runtimescheduler: 00be5844aa2c7d72fd47293e0798bb41462ecfee
React-timing: 54693ad0872f64127f7cb41675b1be4fd28ea4dc
React-utils: ee370a52b08a000963af1a60c31e6c87a70620a5
ReactCodegen: 5148a0102fc8f0a1f9b05d955da886b44447679d
ReactCommon: b8485556b596ef2f44f59bc586113bda138fb804
RNCAsyncStorage: c91d753ede6dc21862c4922cd13f98f7cfde578e
RNCClipboard: dbcf25b8f666b4685c02eeb65be981d30198e505
RNCMaskedView: 972c098900ec45a5684a6785a7af405e8b0fc1e1
RNCMaskedView: e2e87cbd6366581943892b44176e7976ff988dfd
RNCPicker: d8662eb6615e3401acb590c44b97b2af3beb1e53
RNDeviceInfo: ae26ae45db3f9937f038a284bcd0a1db8d70db96
RNFBApp: 72b96921c64702d51eca9f3ed579c1777efd0d7e
RNFBAppCheck: 9e3bbada601e8c37fd066c04e46afdef5e4a3fed
RNGestureHandler: fc04a2ca677e1d661d94716ef96a441aa98d6c68
RNReactNativeHapticFeedback: c873497ad3f9fa80447baa18daa9474e671d24bf
RNReanimated: f858cf8b4a9a47c8b190347c1a8dacbeab4a3255
RNScreens: f770034511e60c71feee26f9f50a6e1cc617ef9e
RNGestureHandler: 5b24d10761754ad271b714e536c457fd89b17c54
RNReactNativeHapticFeedback: 00ba111b82aa266bb3ee1aa576831c2ea9a9dfad
RNReanimated: 929c26a706dfe1af8feee9f2cf78004394e4dd04
RNScreens: e21c8d32fe97737ecc30f1f21e7b6f69f341a1f5
RNSVG: 6a529f4faed8be4ebfb00f1a29e25cb046d95e61
RNVectorIcons: 55221459225ae0fe7a5ab6b029378c79f1a82d8f
RNVectorIcons: 182892e7d1a2f27b52d3c627eca5d2665a22ee28
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 748f06daed00132bf0a051dbb2f4347660ac1a98
Yoga: 3deb2471faa9916c8a82dda2a22d3fba2620ad37

PODFILE CHECKSUM: e7d96885936750d384ed051dda70a66b2604e73a
PODFILE CHECKSUM: 32a4153d1beca6e668aaf0a6895592c98472b30c

COCOAPODS: 1.16.2
1 change: 0 additions & 1 deletion jest/fixtures/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const mockDefaultCompletionParams: CompletionParams = {
mirostat: 0,
mirostat_tau: 5,
mirostat_eta: 0.1,
penalize_nl: false,
seed: 0,
n_probs: 0,
stop: ['</s>'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@dr.pogodin/react-native-fs": "^2.30.1",
"@flyerhq/react-native-link-preview": "^1.6.0",
"@gorhom/bottom-sheet": "^5.0.6",
"@pocketpalai/llama.rn": "0.4.3-1",
"@pocketpalai/llama.rn": "^0.4.7-2",
"@react-native-async-storage/async-storage": "^2.1.0",
"@react-native-clipboard/clipboard": "^1.15.0",
"@react-native-community/blur": "^4.4.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,6 @@ export const BenchResultCard = ({result, onDelete, onShare}: Props) => {
<Text style={styles.infoIcon}></Text>
</View>
</Tooltip>
) : result.config.label === 'Custom' ? (
<Tooltip title="Custom benchmark results cannot be shared">
<View style={styles.tooltipContainer}>
<Text variant="bodySmall" style={styles.disabledText}>
Cannot share
</Text>
<Text style={styles.infoIcon}></Text>
</View>
</Tooltip>
) : (
<View style={styles.actionContainer}>
<Button
Expand Down
26 changes: 23 additions & 3 deletions src/screens/BenchmarkScreen/BenchmarkScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const DEFAULT_CONFIGS: BenchmarkConfig[] = [

const BENCHMARK_PARAMS_METADATA = {
pp: {
validation: {min: 64, max: 2048},
descriptionKey: 'Number of prompt processing tokens',
validation: {min: 64, max: 4096},
descriptionKey:
'Number of prompt processing tokens (max: physical batch size)',
},
tg: {
validation: {min: 32, max: 2048},
Expand Down Expand Up @@ -267,6 +268,16 @@ export const BenchmarkScreen: React.FC = observer(() => {
}
};

const getMaxPPValue = () => {
if (!modelStore.activeContextSettings) {
return BENCHMARK_PARAMS_METADATA.pp.validation.max;
}
return Math.min(
modelStore.activeContextSettings.n_ubatch,
BENCHMARK_PARAMS_METADATA.pp.validation.max,
);
};

const renderModelSelector = () => (
<Menu
visible={showModelMenu}
Expand Down Expand Up @@ -315,7 +326,11 @@ export const BenchmarkScreen: React.FC = observer(() => {
testID={testId ?? `${name}-slider`}
style={styles.slider}
minimumValue={BENCHMARK_PARAMS_METADATA[name].validation.min}
maximumValue={BENCHMARK_PARAMS_METADATA[name].validation.max}
maximumValue={
name === 'pp'
? getMaxPPValue()
: BENCHMARK_PARAMS_METADATA[name].validation.max
}
step={step}
value={localSliderValues[name] ?? selectedConfig[name]}
onValueChange={value => {
Expand All @@ -330,6 +345,11 @@ export const BenchmarkScreen: React.FC = observer(() => {
<View style={styles.sliderDescriptionContainer}>
<Text style={styles.description}>
{BENCHMARK_PARAMS_METADATA[name].descriptionKey}
{name === 'pp' && modelStore.activeContextSettings && (
<Text style={styles.maxValueHint}>
{` (max: ${getMaxPPValue()})`}
</Text>
)}
</Text>
<Text style={styles.settingValue}>
{Number.isInteger(step)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const DeviceInfoCard = ({onDeviceInfo, testId}: Props) => {
{Platform.OS === 'android' && (
<View style={styles.deviceInfoRow}>
<Text variant="labelSmall" style={styles.deviceInfoLabel}>
ML Instructions
Instructions
</Text>
<Text variant="bodySmall" style={styles.deviceInfoValue}>
FP16: {deviceInfo.cpuDetails.hasFp16 ? '✓' : '✗'}, DotProd:{' '}
Expand Down
4 changes: 4 additions & 0 deletions src/screens/BenchmarkScreen/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@ export const createStyles = (theme: Theme) =>
marginLeft: 12,
flex: 1,
},
maxValueHint: {
color: theme.colors.onSurfaceVariant,
fontStyle: 'italic',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const CompletionSettings: React.FC<Props> = ({settings, onChange}) => {
);
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const renderSwitch = (name: string) => (
<View style={[styles.settingItem, styles.row]}>
<View>
Expand Down Expand Up @@ -212,7 +213,6 @@ export const CompletionSettings: React.FC<Props> = ({settings, onChange}) => {
{renderSlider({name: 'mirostat_eta'})}
</>
)}
{renderSwitch('penalize_nl')}
{renderIntegerInput({name: 'seed'})}
{renderStopWords()}
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ describe('CompletionSettings', () => {
const mirostatEtaSlider = getByTestId('mirostat_eta-slider');
expect(mirostatEtaSlider.props.value).toBe(0.1);

expect(getByTestId('penalize_nl-switch')).toBeTruthy();
const penalizeNlSwitch = getByTestId('penalize_nl-switch');
expect(penalizeNlSwitch.props.value).toBe(false);

expect(getByTestId('seed-input')).toBeTruthy();
const seedInput = getByTestId('seed-input');
expect(seedInput.props.value).toBe('0');
Expand Down Expand Up @@ -113,20 +109,6 @@ describe('CompletionSettings', () => {
expect(mockOnChange).toHaveBeenCalledWith('n_predict', '1024');
});

it('handles switch toggle', () => {
const mockOnChange = jest.fn();
const {getByTestId} = render(
<CompletionSettings
settings={mockCompletionParams}
onChange={mockOnChange}
/>,
);

const penalizeNlSwitch = getByTestId('penalize_nl-switch');
fireEvent(penalizeNlSwitch, 'valueChange', false);
expect(mockOnChange).toHaveBeenCalledWith('penalize_nl', false);
});

it('handles chip selection', () => {
const mockOnChange = jest.fn();
const {getByText} = render(
Expand Down
Loading

0 comments on commit 62c9126

Please sign in to comment.