--- license: apache-2.0 language: - en base_model: mlx-community/Qwen3-8B-4bit tags: - mlx - lora - distillation - code - swift - text-generation pipeline_tag: text-generation vertex_family: codein vertex_params: "8B" vertex_purpose: "Swift coding specialist" vertex_result: "38% of held-out prompts produce working, swiftc-typechecked code within a 512-token budget (base: 0%, exhausted by unbounded chain-of-thought before reaching any code)" vertex_status: released vertex_name: "CodeInSwift 1 Small" vertex_base: "Qwen3-8B" --- # CodeInSwift 1 Small **A Swift coding specialist, distilled from real instruction/response data into Qwen3-8B** Part of the **CodeIn** family: where Aquamarine is a generalist across languages, CodeIn models go the other direction -- each one distilled for exactly one programming language, and nothing else. CodeInSwift is the second: Apple's Swift. ## Overview CodeInSwift 1 Small is fine-tuned via LoRA on **Qwen3-8B** to act as a Swift coding assistant -- given a problem description, it explains its approach and writes complete, correct Swift code, as a real chat model (not raw code completion, unlike its CodeInLuau sibling, since this dataset is genuine 2-turn instruction/response data). ## Training - **Base model:** `mlx-community/Qwen3-8B-4bit` - **Dataset:** [`MnemicAI/Ling-Coder-SFT-English-Clean`](https://huggingface.co/datasets/MnemicAI/Ling-Coder-SFT-English-Clean), Swift split -- 68,301 rows of genuine human/assistant coding Q&A, split 92/8 into 62,837 train / 5,464 validation examples. - **Method:** LoRA fine-tuning (rank 8, scale 20, 16 layers), 9,600 iterations across 3 resumed sessions, batch size 1, sequence length 3072, trained as a real chat model via a fixed system prompt + `messages` format. - **Val loss:** 0.652 at the end of training. ## Evaluation A held-out base-vs-tuned comparison used 100 prompts sampled from the dataset's own validation split (`valid.jsonl`, never touched during training), each fed the same system prompt and user question, with greedy decoding capped at 512 output tokens. Outputs were classified by extracting any ` ```swift ` code block and running it through the real Swift compiler (`swiftc -typecheck`) -- a genuine correctness oracle, not a heuristic or LLM judge. | | compiles cleanly | compile error | no code block reached | |---|---|---|---| | **Base Qwen3-8B** | 0 | 0 | **100** | | **CodeInSwift 1 Small** | **38** | 19 | 43 | The base model's 0/100 is not a claim that it can't write Swift -- Qwen3-8B is a reasoning model, and unprompted it spends the entire 512-token budget inside a `` block reasoning through the approach, never reaching a code fence at all (verified by inspecting the raw transcripts). CodeInSwift has learned to skip that and deliver a working, correctly-formatted answer inside a practical response budget, which is what actually matters for an interactive coding assistant. Even so, the tuned model's own remaining 43% no-code-block rate and 19% compile-error rate are real, unresolved gaps -- reported here rather than glossed over. ## Usage ```python from mlx_lm import load, generate model, tokenizer = load("VertexAGI/codeinswift-1-small") messages = [ {"role": "system", "content": "You are CodeInSwift, a coding specialist for the Swift programming language. Given a coding problem, explain your problem-solving approach clearly, then provide complete, correct Swift code."}, {"role": "user", "content": "Write a function that reverses a linked list in place."}, ] prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False) response = generate(model, tokenizer, prompt=prompt, max_tokens=512) print(response) ``` This is a chat model -- use the system prompt above (or your own) plus a real question, not a raw code prefix. ## Formats available MLX only for this release (4-bit, via `mlx-lm`, for Apple Silicon). No GGUF yet -- same reason as CodeInLuau: the dequantize-to-fp16-then-quantize conversion path needs disk headroom this machine didn't have available at release time; may follow later. ## Limitations An 8B-parameter model fine-tuned via LoRA on ~63K examples. The evaluation above shows real, unresolved gaps -- a meaningful fraction of responses either don't produce a compilable code block within a practical response length or contain genuine compile errors. Treat output as a strong starting point to review and compile yourself, not code to ship unread. ## License Apache 2.0, inherited from the Qwen3 base model.