new features

This commit is contained in:
Mark Gregory
2026-11-18 13:55:47 +00:00
parent 17bcf178a9
commit a07ddf4d6d
29 changed files with 3457 additions and 306 deletions
+88 -51
View File
@@ -95,6 +95,8 @@ final class TrainingOperation: ObservableObject {
process.standardInput = FileHandle.nullDevice
var environment = ProcessInfo.processInfo.environment
environment["PYTHONUNBUFFERED"] = "1"
environment["NO_COLOR"] = "1"
environment["TERM"] = "dumb"
environment["PATH"] = executable.deletingLastPathComponent().path + ":" + (environment["PATH"] ?? "/usr/bin:/bin")
process.environment = environment
let pipe = Pipe()
@@ -118,7 +120,7 @@ final class TrainingOperation: ObservableObject {
}
private func append(_ text: String) {
log += text
log += text.replacingOccurrences(of: "\u{001B}\\[[0-?]*[ -/]*[@-~]", with: "", options: .regularExpression)
if log.count > 80_000 { log = String(log.suffix(60_000)) }
}
}
@@ -133,6 +135,14 @@ struct ModelWorkshop: Identifiable {
struct ModelWorkshopView: View {
let workshop: ModelWorkshop
let register: (URL) -> Void
let embedded: Bool
private enum Stage: String, CaseIterable, Identifiable {
case setup = "Tools", convert = "Convert", train = "Train"
var id: Self { self }
}
@State private var stage: Stage = .train
@Environment(\.dismiss) private var dismiss
@AppStorage("trainingInstallerPython") private var installerPython = ""
@@ -147,9 +157,10 @@ struct ModelWorkshopView: View {
@State private var iterations = 50
@State private var layers = 4
init(workshop: ModelWorkshop, register: @escaping (URL) -> Void) {
init(workshop: ModelWorkshop, embedded: Bool = false, register: @escaping (URL) -> Void) {
self.workshop = workshop
self.register = register
self.embedded = embedded
_base = State(initialValue: workshop.base)
}
@@ -167,56 +178,76 @@ struct ModelWorkshopView: View {
var body: some View {
VStack(spacing: 0) {
Form {
Section("MLX Tools") {
LabeledContent("Environment", value: toolsInstalled ? "Installed" : "Setup required")
HStack {
Button(toolsInstalled ? "Reinstall MLX Tools" : "Install MLX Tools", action: install)
Button("Choose Python…") {
if let url = selectURL(folders: false) { installerPython = url.path }
}
}
Text(installerPython.isEmpty ? "Uses a local Python 3.11 or newer to set up a dedicated environment." : installerPython)
if embedded {
VStack(alignment: .leading, spacing: 10) {
Text("Training").font(.largeTitle.weight(.semibold))
Label(toolsInstalled ? "MLX tools ready" : "MLX tools setup required",
systemImage: toolsInstalled ? "checkmark.circle.fill" : "info.circle")
.foregroundStyle(.secondary)
Picker("Training stage", selection: $stage) {
ForEach(Stage.allCases) { Text($0.rawValue).tag($0) }
}.pickerStyle(.segmented).labelsHidden().frame(maxWidth: 340)
}
Section("Convert to MLX") {
if let name = workshop.modelName {
Text("For \(name), select its original Hugging Face checkpoint. Ollama GGUF files cannot be converted by MLX LM.")
.frame(maxWidth: .infinity, alignment: .leading)
.padding(20)
Divider()
}
Form {
if !embedded || stage == .setup {
Section("MLX Tools") {
LabeledContent("Environment", value: toolsInstalled ? "Installed" : "Setup required")
HStack {
Button(toolsInstalled ? "Reinstall MLX Tools" : "Install MLX Tools", action: install)
Button("Choose Python…") {
if let url = selectURL(folders: false) { installerPython = url.path }
}
}
Text(installerPython.isEmpty ? "Uses a local Python 3.11 or newer to set up a dedicated environment." : installerPython)
.foregroundStyle(.secondary)
}
if let sourceFolder {
LabeledContent("Checkpoint", value: sourceFolder.path)
} else {
TextField("Hugging Face repository", text: $repository, prompt: Text("owner/model"))
TextField("Revision", text: $revision, prompt: Text("Optional commit or tag"))
}
HStack {
Button("Choose Checkpoint Folder…") { if let url = selectURL() { sourceFolder = url } }
if sourceFolder != nil { Button("Use Hugging Face Repository") { sourceFolder = nil } }
if !embedded || stage == .convert {
Section("Convert to MLX") {
if let name = workshop.modelName {
Text("For \(name), select its original Hugging Face checkpoint. Ollama GGUF files cannot be converted by MLX LM.")
.foregroundStyle(.secondary)
}
if let sourceFolder {
LabeledContent("Checkpoint", value: sourceFolder.path)
} else {
TextField("Hugging Face repository", text: $repository, prompt: Text("owner/model"))
TextField("Revision", text: $revision, prompt: Text("Optional commit or tag"))
}
HStack {
Button("Choose Checkpoint Folder…") { if let url = selectURL() { sourceFolder = url } }
if sourceFolder != nil { Button("Use Hugging Face Repository") { sourceFolder = nil } }
}
Toggle("Quantize to 4-bit", isOn: $quantize)
Button("Convert and Register…", action: convert)
.disabled(!toolsInstalled || (sourceFolder == nil && repository.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty))
}
Toggle("Quantize to 4-bit", isOn: $quantize)
Button("Convert and Register…", action: convert)
.disabled(!toolsInstalled || (sourceFolder == nil && repository.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty))
}
Section("Clone and Train") {
LabeledContent("Base checkpoint", value: base?.path ?? "Choose a converted MLX folder")
HStack {
Button("Choose Base…") { if let url = selectURL() { base = url } }
Button("Clone Base…", action: clone).disabled(base == nil)
}
LabeledContent("Dataset", value: datasetPath.isEmpty ? "No folder selected" : datasetPath)
Button("Choose Dataset…") { if let url = selectURL() { datasetPath = url.path } }
Text("Use a folder containing train.jsonl, valid.jsonl and test.jsonl with text chat examples.")
.foregroundStyle(.secondary)
LabeledContent("Run folder", value: projectPath.isEmpty ? "No folder selected" : projectPath)
Button("Choose Run Folder…") { if let url = selectURL(create: true) { projectPath = url.path } }
Stepper("Training iterations: \(iterations)", value: $iterations, in: 1...100_000)
Stepper("Adapted layers: \(layers)", value: $layers, in: 1...256)
HStack {
Button("Validate Dataset") { train(.validate) }.disabled(!toolsInstalled || datasetPath.isEmpty)
Button("Train Adapter") { train(.train) }.disabled(!ready || datasetPath.isEmpty)
Button("Evaluate") { train(.evaluate) }.disabled(!ready || datasetPath.isEmpty)
Button("Fuse and Register") { train(.fuse) }.disabled(!ready)
if !embedded || stage == .train {
Section("Clone and Train") {
LabeledContent("Base checkpoint", value: base?.path ?? "Choose a converted MLX folder")
HStack {
Button("Choose Base…") { if let url = selectURL() { base = url } }
Button("Clone Base…", action: clone).disabled(base == nil)
}
LabeledContent("Dataset", value: datasetPath.isEmpty ? "No folder selected" : datasetPath)
Button("Choose Dataset…") { if let url = selectURL() { datasetPath = url.path } }
Text("Use a folder containing train.jsonl, valid.jsonl and test.jsonl with text chat examples.")
.foregroundStyle(.secondary)
LabeledContent("Run folder", value: projectPath.isEmpty ? "No folder selected" : projectPath)
Button("Choose Run Folder…") { if let url = selectURL(create: true) { projectPath = url.path } }
Stepper("Training iterations: \(iterations)", value: $iterations, in: 1...100_000)
Stepper("Adapted layers: \(layers)", value: $layers, in: 1...256)
HStack {
Button("Validate Dataset") { train(.validate) }.disabled(!toolsInstalled || datasetPath.isEmpty)
Button("Train Adapter") { train(.train) }.disabled(!ready || datasetPath.isEmpty)
Button("Evaluate") { train(.evaluate) }.disabled(!ready || datasetPath.isEmpty)
Button("Fuse and Register") { train(.fuse) }.disabled(!ready)
}
}
}
}
@@ -224,11 +255,16 @@ struct ModelWorkshopView: View {
.disabled(busy)
Divider()
VStack(alignment: .leading, spacing: 8) {
if embedded { Text("Run output").font(.headline) }
if !operation.log.isEmpty {
ScrollView {
Text(operation.log).font(.system(.caption, design: .monospaced))
.textSelection(.enabled).frame(maxWidth: .infinity, alignment: .leading)
}.frame(height: 112)
ScrollViewReader { proxy in
ScrollView {
Text(operation.log).font(.system(.caption, design: .monospaced))
.textSelection(.enabled).frame(maxWidth: .infinity, alignment: .leading)
.id("run-end")
}
.onChange(of: operation.log) { proxy.scrollTo("run-end", anchor: .bottom) }
}.frame(height: embedded ? 145 : 112)
}
HStack {
if let active = operation.active {
@@ -239,13 +275,14 @@ struct ModelWorkshopView: View {
Text(operation.status).textSelection(.enabled)
}
Spacer()
Button("Done") { dismiss() }.disabled(busy)
if !embedded { Button("Done") { dismiss() }.disabled(busy) }
}
}
.padding(12)
}
.frame(width: 660, height: 585)
.frame(width: embedded ? nil : 660, height: embedded ? nil : 585)
.interactiveDismissDisabled(busy)
.onAppear { if embedded && !toolsInstalled { stage = .setup } }
}
private var ready: Bool { toolsInstalled && base != nil && !projectPath.isEmpty }