Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ models/*

arm_neon.h
compile_commands.json

project.xcworkspace/xcuserdata/
xcuserdata/
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,10 @@ You can also try to quantize the `ggml` models via 4-bit integer quantization.
| --- | --- | --- | --- |
| `bigcode/gpt_bigcode-santacoder` | 5396.45 MB | 1026.83 MB | 4-bit integer (q4_1) |
| `bigcode/starcoder` | 71628.23 MB | 13596.23 MB | 4-bit integer (q4_1) |

## iOS App

The repo includes a proof-of-concept iOS app in the `StarCoderApp` directory. You need to provide the converted (and possibly quantized) model weights, placing a file called `bigcode_ggml_model.bin.bin` inside that folder. This is what it looks like on an iPhone:

![starcoder-ios-screenshot](assets/starcoder-ios.png)

567 changes: 567 additions & 0 deletions StarCoderApp/StarCoder.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"images" : [
{
"filename" : "BigCode Logo Transparent.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions StarCoderApp/StarCoder/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions StarCoderApp/StarCoder/Assets.xcassets/logo.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "BigCode Logo.svg",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
100 changes: 100 additions & 0 deletions StarCoderApp/StarCoder/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// ContentView.swift
// StarCoder
//
// Created by Pedro Cuenca on 15/5/23.
//

import SwiftUI
import Dispatch

class ModelState: ObservableObject {
@Published var model: OpaquePointer? = nil

var modelPath: String {
Bundle.main.path(forResource: "bigcode_ggml_model", ofType: "bin")!
}

func load() {
DispatchQueue.global(qos: .userInitiated).async {
let begin = Date()
let model = load_model(self.modelPath)
DispatchQueue.main.async { self.model = model }
print("Loaded \(String(describing: model)) in \(Date().timeIntervalSince(begin))")
}
}
}

struct ContentView: View {
@State private var prompt: String = "def fibonacci("
@State private var generated: String = ""
@State private var generating: Bool = false
@State private var status: String = ""

@StateObject private var modelState = ModelState()
private var modelIsLoaded: Bool { modelState.model != nil }

func listenToNotifications() {
NotificationCenter.default.addObserver(forName: NSNotification.Name("decoded.token.received"), object: nil, queue: nil) { decoded in
generated = generated.appending(decoded.object as! String)
}
}

func complete(from text: String) {
guard let model = modelState.model else { return }

generating.toggle()
generated = text
status = ""

DispatchQueue.global(qos: .userInteractive).async {
func token_callback(char_ptr: UnsafePointer<CChar>?) {
guard let char_ptr = char_ptr else { return }

// We can't pass a "function that captures context" as a C function pointer, so we resort to posting a notification
DispatchQueue.main.async {
let str = String(cString: char_ptr)
NotificationCenter.default.post(name: NSNotification.Name("decoded.token.received"), object: str)
}
}

let msPerToken = generate(model, text, token_callback)
DispatchQueue.main.async {
status = String(format: "%.2f ms/token", msPerToken)
generating = false
}
}
}

var body: some View {
VStack {
Image("logo").resizable().aspectRatio(contentMode: .fit)
HStack {
TextField("Prompt", text: $prompt, axis: .vertical).lineLimit(2...5)
.textFieldStyle(.roundedBorder)
Button("Complete") {
complete(from: prompt)
}.buttonStyle(.borderedProminent).disabled(!modelIsLoaded)
}
Text(generated).frame(maxWidth: .infinity, alignment: .leading)//.multilineTextAlignment(.leading)
if generating {
ProgressView().padding()
}
Spacer()
if status != "" {
Text(status).font(.system(size: 14)).padding().frame(maxWidth: .infinity).background(Color(white: 0.9))
}
}
.padding()
.onAppear {
listenToNotifications()
modelState.load()
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
5 changes: 5 additions & 0 deletions StarCoderApp/StarCoder/StarCoder-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

#import <starcoderlib/starcoder.h>
17 changes: 17 additions & 0 deletions StarCoderApp/StarCoder/StarCoderApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// StarCoderApp.swift
// StarCoder
//
// Created by Pedro Cuenca on 15/5/23.
//

import SwiftUI

@main
struct StarCoderApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
16 changes: 16 additions & 0 deletions StarCoderApp/StarCoder/starcoder.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// starcoder.xcconfig
// StarCoderApp
//
// Created by Pedro Cuenca on 15/5/23.
//

// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

OTHER_CFLAGS = -O3 -DNDEBUG -std=c11 -fPIC -pthread -mf16c -mfma -mavx -mavx2 -DGGML_USE_ACCELERATE
OTHER_CPLUSPLUSFLAGS = -O3 -DNDEBUG -std=c++11 -fPIC -pthread

GCC_OPTIMIZATION_LEVEL = 3
ENABLE_TESTABILITY = NO
DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
Loading