Qwen3-4B Text-to-SQL LoRA adapter (Quark INT4 base)

LoRA adapter for amd/qwen-3-4B-quark, trained against the INT4-quantized base so it keeps its effect on the AMD Ryzen AI NPU. Published unmerged; applying it to the FP Qwen3-4B will not reproduce these results.

Configuration

rank (r) / alpha 16 / 32 (scaling factor 2.0)
dropout 0.05
target modules q, k, v, o, gate, up, down
epochs 5
training data Spider 1.0 train split

Prompt format

Trained on this exact template; deviating from it degrades accuracy.

SQL_PROMPT = (
    "You are a text-to-SQL assistant. Given a database schema and a question,\n"
    "write a single valid SQL query that answers it.\n\n"
    "### Schema:\n{schema}\n\n### Question:\n{question}\n\n### SQL:\n"
)

Usage

GPU β€” the Quark base dequantizes on the fly, so PEFT attaches normally:

model = import_model_from_safetensors(...)          # amd/qwen-3-4B-quark
model = PeftModel.from_pretrained(model, "amd/qwen-3-4B-spider-sql-lora-adapter")

Ryzen AI NPU β€” compile base and adapter together, then activate by name:

model_generate --npu --token_fusion --output .\qwen3-4b-npu --input .\qwen3-4b-quark-int4 ^
    --extra_options lora lora_adapter=.\adapter_model.safetensors lora_name=sql_spider lora_scaling_factor=2.0
import onnxruntime_genai as og
from ryzenai_onnx_utils import set_active_adapter

model = og.Model(".\\qwen3-4b-npu")
set_active_adapter("sql_spider")   # activate
set_active_adapter("base")         # revert

lora_scaling_factor must equal alpha / r (2.0). The scale is applied at compile time; there is no runtime dial.

Full walkthrough, accuracy results, and eval scripts: Dynamic LoRA example.

Limitations

Specialized for text-to-SQL in the prompt format above; not a general-purpose instruction adapter. Validate generated SQL before running it against real data.

License

Modifications copyright(c) 2025 Advanced Micro Devices, Inc. All rights reserved. AMD has modified the original model files for optimized deployment on AMD Ryzen AI hardware.

MIT License

Copyright (c) 2025 Advanced Micro Devices, Inc

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Base Model License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Dataset License

Spider 1.0 is released under CC BY-SA 4.0.


EULA & Third Party Notices

For the End User License Agreement (EULA) and Third Party Notices (TPN), see Ryzen AI Licenses.

Downloads last month
15
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for amd/qwen-3-4B-spider-sql-lora-adapter

Adapter
(2)
this model

Dataset used to train amd/qwen-3-4B-spider-sql-lora-adapter