File size: 3,317 Bytes
f895015
 
e405197
 
 
 
 
 
 
 
 
 
 
 
f895015
e405197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: apache-2.0
base_model: Qwen/Qwen3-8B
base_model_relation: adapter
library_name: peft
pipeline_tag: text-generation
language:
- zh
tags:
- lora
- qwen3
- orcaflex
- ocean-engineering
- code-generation
---

# OceanCoder

OceanCoder is a LoRA adapter for [Qwen/Qwen3-8B](https://huggingface.co/Qwen/Qwen3-8B) trained to generate Python (`OrcFxAPI`) OrcaFlex modelling scripts from Chinese ocean-engineering specifications.

## Model Details

- **Base model:** `Qwen/Qwen3-8B` (`revision: b968826d9c46dd6066d109eabc6255188de91218`)
- **Adapter:** LoRA (`r=16`, `lora_alpha=32`, `lora_dropout=0.05`, applied to `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` across all 36 layers)
- **Training:** SFT, GRPO (step 57), and SFT continuation (460 examples, 58 updates); accumulated weights load directly onto `Qwen/Qwen3-8B`
- **Language:** Chinese prompts (`zh`), Python / `OrcFxAPI` code output
- **License:** Apache-2.0

## Usage

Tested with `transformers==4.57.6`, `peft==0.20.0`, `accelerate==1.15.0`, `bitsandbytes==0.50.2`, and `safetensors==0.7.0` on CUDA-enabled PyTorch.

```python
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig

adapter_path = "."
tokenizer = AutoTokenizer.from_pretrained(adapter_path)
base_model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen3-8B",
    revision="b968826d9c46dd6066d109eabc6255188de91218",
    quantization_config=BitsAndBytesConfig(
        load_in_4bit=True,
        bnb_4bit_quant_type="nf4",
        bnb_4bit_use_double_quant=True,
        bnb_4bit_compute_dtype=torch.bfloat16,
    ),
    dtype=torch.bfloat16,
    device_map="auto",
)
model = PeftModel.from_pretrained(base_model, adapter_path, is_trainable=False).eval()

messages = [
    {"role": "user", "content": "请用 OrcFxAPI 建立一根水深 100 m 的单根系泊链静力模型并保存为 model.dat。"}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True,
    enable_thinking=False,
)
inputs = tokenizer([text], return_tensors="pt").to(model.device)

with torch.no_grad():
    output_ids = model.generate(**inputs, max_new_tokens=2048, do_sample=False)

print(tokenizer.decode(output_ids[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
```

Pass `enable_thinking=False` to `apply_chat_template` for non-thinking code generation. Omit `quantization_config` if loading the base model in full `bfloat16` (or merging adapters via `model.merge_and_unload()`).

## Benchmark

The companion evaluation suite **OceanCoder-Benchmark** (665 Chinese OrcaFlex 11.6 engineering modelling tasks) is released as a separate Hugging Face dataset repository. Executing generated scripts requires a licensed OrcaFlex 11.6 (`OrcFxAPI`) installation.

## License

- The OceanCoder LoRA adapter weights (`adapter_model.safetensors`), configuration (`adapter_config.json`), and documentation are released under the **Apache License 2.0** (`LICENSE`).
- The base model and packaged tokenizer files originate from [Qwen/Qwen3-8B](https://huggingface.co/Qwen/Qwen3-8B) under the Apache License 2.0 (`LICENSE-Qwen3.txt`), with `chat_template.jinja` exported separately via `transformers`.
- OrcaFlex and OrcFxAPI are trademarks of Orcina Ltd.