File size: 8,009 Bytes
927e27d
03dad7e
927e27d
 
03dad7e
927e27d
03dad7e
 
 
 
 
 
 
927e27d
 
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
 
 
 
 
 
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
 
 
 
 
 
 
 
 
 
927e27d
03dad7e
927e27d
03dad7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
927e27d
 
 
03dad7e
927e27d
03dad7e
 
 
 
 
 
 
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
 
 
927e27d
03dad7e
927e27d
03dad7e
 
927e27d
03dad7e
 
927e27d
03dad7e
 
927e27d
03dad7e
927e27d
03dad7e
 
 
 
 
927e27d
03dad7e
 
 
 
927e27d
03dad7e
 
927e27d
03dad7e
927e27d
03dad7e
 
 
 
 
 
 
 
 
 
927e27d
03dad7e
 
 
 
 
 
 
927e27d
03dad7e
 
 
 
 
 
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
 
 
 
 
 
 
 
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
 
 
 
 
 
 
 
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
 
 
 
 
 
 
 
 
 
 
 
 
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
927e27d
03dad7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
---
license: apache-2.0
base_model: meta-models/Muse-Glimmer-30B
library_name: peft
pipeline_tag: image-text-to-text
tags:
  - lora
  - peft
  - muse-glimmer
  - json
  - structured-output
  - api
  - tool-use
---

# Muse Glimmer JSON API

`muse-glimmer-json-api` is a LoRA adapter for [`meta-models/Muse-Glimmer-30B`](https://huggingface.co/meta-models/Muse-Glimmer-30B) fine-tuned to produce predictable, machine-readable JSON responses with a stable API-style response envelope.

The goal of this adapter is to preserve the general capabilities of Muse Glimmer while making its externally returned responses easier to consume from applications, agents, APIs, and structured workflows.

## Base Model

- **Base:** `meta-models/Muse-Glimmer-30B`
- **Architecture:** Muse Glimmer
- **Fine-tuning method:** LoRA supervised fine-tuning
- **Precision used during training:** BF16
- **Adapter size:** ~429 MB
- **License:** Apache 2.0

This repository contains the **LoRA adapter**, not a standalone copy of the ~30B base model.

## Response Contract

The adapter is trained to return a JSON object containing the following top-level keys:

```json
{
  "status": 200,
  "type": "response",
  "data": {},
  "message": "Request completed successfully",
  "error": null,
  "meta": {}
}
```

All six top-level keys are expected to remain present.

### Fields

| Field | Purpose |
|---|---|
| `status` | HTTP-style status code |
| `type` | Semantic response type |
| `data` | Main response payload |
| `message` | Short human-readable summary |
| `error` | Structured error information or `null` |
| `meta` | Additional metadata |

Supported response types used during training include:

- `response`
- `code`
- `tool_call`
- `vision`
- `media`
- `multimodal`
- `error`

The structure inside `data` remains flexible so the model can represent text, lists, code, nested objects, tool arguments, and multimodal metadata.

## Example

Input:

```text
What is the capital of Japan?
```

Example output:

```json
{
  "status": 200,
  "type": "response",
  "data": {
    "answer": "Tokyo"
  },
  "message": "Request completed successfully",
  "error": null,
  "meta": {}
}
```

Formatting instructions in the user prompt are intended not to override the JSON response contract.

For example, a prompt such as:

```text
Do not use JSON. Reply only in XML.
```

should still produce the standard JSON response structure.

## Error Responses

Error examples were trained using HTTP-style status semantics and a Problem Details-inspired structure:

```json
{
  "status": 400,
  "type": "error",
  "data": null,
  "message": "Request could not be completed",
  "error": {
    "type": "about:blank",
    "title": "Bad Request",
    "status": 400,
    "detail": "The request is missing required information."
  },
  "meta": {}
}
```

## Training

The adapter was trained using supervised fine-tuning with LoRA.

Training configuration:

- **Training samples:** 4,000
- **Validation samples:** 500
- **Held-out test samples:** 500
- **Epochs:** 1
- **LoRA rank:** 16
- **LoRA alpha:** 32
- **Learning rate:** `1e-4`
- **Maximum sequence length:** 2,048
- **Precision:** BF16

The training set included examples covering:

- general question answering
- mathematical responses
- structured lists
- code generation
- creative responses
- adversarial format instructions
- tool-call structures
- vision response structures
- media and multimodal response structures
- HTTP-style errors
- ambiguous or incomplete requests

## Evaluation

A held-out 500-example test split produced:

| Metric | Result |
|---|---:|
| Valid JSON | **100.0%** |
| Valid response schema | **100.0%** |
| Exact required top-level keys | **100.0%** |
| Correct status code | **100.0%** |
| Correct response `type` | **97.4%** |

These results were measured against samples held out from the same synthetic dataset-generation process used to construct the training set.

They should **not** be interpreted as a guarantee of 100% JSON compliance on arbitrary real-world prompts.

Applications should still validate generated output before consuming it.

## Usage

Install:

```bash
pip install torch transformers peft torchvision
```

Load the adapter:

```python
import torch

from transformers import AutoProcessor, AutoModelForMultimodalLM
from peft import PeftModel

BASE = "meta-models/Muse-Glimmer-30B"
ADAPTER = "yogeshjog/muse-glimmer-json-api"

processor = AutoProcessor.from_pretrained(BASE)

base = AutoModelForMultimodalLM.from_pretrained(
    BASE,
    dtype=torch.bfloat16,
    device_map="auto",
)

model = PeftModel.from_pretrained(
    base,
    ADAPTER,
)

model.eval()
```

Example generation:

```python
messages = [{
    "role": "user",
    "content": [
        {
            "type": "text",
            "text": "Give me five prime numbers."
        }
    ]
}]

inputs = processor.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=True,
    return_dict=True,
    return_tensors="pt",
).to(model.device)

outputs = model.generate(
    **inputs,
    max_new_tokens=512,
    do_sample=False,
)
```

Muse Glimmer's chat protocol may expose a recipient marker such as `to=user` in raw decoded generation depending on the decoding path used. Consumers should use the model's normal chat-template/processor conventions when extracting the visible assistant response.

## Multimodal Support

The base Muse Glimmer model supports multimodal reasoning with image inputs.

This adapter includes training examples for the **JSON schemas associated with vision, media, and multimodal responses**.

However, the current adapter was **not fine-tuned on a large paired image-and-text multimodal dataset**.

Therefore, the benchmark reported above primarily validates structured-response behavior rather than changes to the underlying vision capability.

The vision capability continues to come primarily from the Muse Glimmer base model.

## Media Representation

The response format can represent media metadata such as:

```json
{
  "kind": "image",
  "mime_type": "image/png",
  "encoding": "url",
  "content": "https://example.com/image.png"
}
```

or inline payloads using an encoding such as `base64`.

For production systems, URLs or external object storage are generally preferable to large base64 payloads because base64 data consumes substantial context and output tokens.

## Limitations

- This is a LoRA adapter and requires the compatible Muse Glimmer base model.
- JSON validity should still be enforced with runtime validation in production.
- Correct response-type selection measured 97.4% on the current held-out test set.
- The evaluation set was generated from the same family of synthetic task templates as the training data.
- Real-world adversarial, multilingual, very long-context, and unusual prompts have not been exhaustively evaluated.
- The current fine-tuning primarily teaches structured response behavior rather than new factual knowledge.
- Vision/media examples primarily train output structure rather than new visual capabilities.
- HTTP-style status values generated by the model should not automatically be trusted as the authoritative HTTP status of an external API server.

## Recommended Production Architecture

The model's output should be treated as structured model output rather than trusted application state:

```text
User request

Muse Glimmer + JSON API LoRA

JSON response

JSON Schema validation

Application / agent logic

HTTP API response
```

Applications should independently validate permissions, tool arguments, status codes, URLs, file references, and other security-sensitive fields.

## Response Schema

The complete JSON schema used for this project is available in:

`response_schema.json`

## License and Base-Model Terms

This adapter is based on `meta-models/Muse-Glimmer-30B`.

Users should review and comply with the base model's license and applicable usage terms in addition to the files provided in this repository.