Compliance Fine-Tuning and Local Deployment Practices for Mid-Sized Open-Source LLMs
This article explores practical strategies for fine-tuning and locally deploying mid-sized open-source Large Language Models (LLMs) while ensuring compliance. It covers mitigating over-refusal issues through compliant alignment, calculating VRAM for quantized deployment, validating tokenizers and tool-calling capabilities for inference acceleration, and optimizing multi-turn dialogue stability. Readers will learn how to establish stable, controllable, and compliant local LLM services through reproducible measurement and rigorous validation.
1. Over-Refusal Issues and Compliance Alignment Fine-Tuning
Open-source base models typically ingest a large number of refusal samples during the safety alignment phase. In professional business contexts, this can lead to normal instructions being rejected, such as in medical science popularization, code security auditing, and legal clause interpretation. The industry often uses the “False Refusal Rate” to measure this problem, calculated as the number of incorrectly rejected normal samples divided by the total number of normal samples. It is recommended to first build an evaluation set containing hundreds of normal professional instructions, categorize and count false refusal samples, and then identify the domains where the problem is concentrated.
For false refusal issues, fine-tuning must be premised on compliance. Common practices include: supplementing normal Q&A samples with audited instruction data from business scenarios; retaining and strengthening refusal samples for illegal and harmful requests so the model can distinguish between professional consultation and harmful requests; and retaining an independent content security filter layer outside the model, with the business side responsible for input/output review, log retention, and manual re-checking. The model itself should not be treated as the security boundary.
This article does not discuss removing or bypassing safety mechanisms. Any fine-tuning should comply with local laws and regulations, platform terms of service, and model license requirements. Public-facing services should complete a security assessment before launch.
During evaluation, three types of metrics should be monitored simultaneously: false refusal rate, harmful request pass rate, and task completion rate. If only the false refusal rate decreases while the harmful request pass rate significantly increases, it indicates that the fine-tuning has introduced risks, requiring data rollback or ratio adjustment.
2. Quantized Deployment and VRAM Calculation
The size of native FP16 weights is substantial. Taking a 26B parameter model as an example, the weights alone require about 50GB of VRAM. Q4_K_M is a mixed-precision quantization scheme: most weights are stored using 4-bit integers, while some key layers (such as certain projection layers in the attention mechanism) retain 6-bit or 8-bit precision, striking a balance between model size and precision loss.
Under this scheme, the weight file is about 13GB to 14GB. The total VRAM usage also includes the KV Cache, inference framework temporary buffers, and runtime overhead. The “approximately 16.8GB” reported in the community is measured under specific conditions and is not a universal value. When reproducing, at least the following information should be recorded: the specific model version and quantized file name, inference framework and version, context length, batch size, KV Cache precision, GPU layers (i.e., offload ratio), system memory capacity, and driver version.
On a graphics card with 16GB of VRAM, some layers need to be offloaded to system memory for operation. In this case, the generation speed will drop noticeably, and the exact speed depends on memory bandwidth and CPU performance. Whether it can run stably also depends on the context length and concurrency. It is recommended to load the model with a short context first, gradually increase the context length, and record the peak VRAM usage.
Framework selection can be considered based on the scenario. llama.cpp with the GGUF format is suitable for single-machine, low-resource scenarios that require flexible allocation of GPU layers. Ollama wraps model management and local service interfaces, making it suitable for rapid verification. vLLM is better suited for high-concurrency services but has higher requirements for VRAM and GPU models, meaning not all 16GB devices can use it stably. Before selection, verify the framework’s support for the target model architecture and quantized format.
Containerized deployment helps fix dependency versions. It is recommended to use images to fix CUDA, driver-related libraries, and inference framework versions, and mount model files in read-only mode. Runtime logs and metrics can be integrated into standard monitoring systems to record VRAM usage, response latency, and error rates.
3. Inference Acceleration and Tokenizer/Tool-Calling Validation
Community fine-tuned models often claim significant improvements in inference speed. Such figures usually depend on hardware, model version, input/output length, and concurrency; percentages detached from these conditions have no reference value. This article does not provide absolute improvement ratios. Readers should use fixed inputs in their own environments for baseline comparison, recording Time to First Token and Tokens generated per second.
For acceleration, PagedAttention manages the KV Cache through paging, reducing VRAM fragmentation, and is suitable for multi-request concurrency scenarios. FlashAttention reduces VRAM read/write operations through block calculation, showing more obvious effects in long-context scenarios. The actual benefits of both depend on framework and hardware support and require real-world testing to confirm.
Tokenizer issues are a common source of failure in local deployment. If special tokens are added or the vocabulary is modified during fine-tuning, but the inference end still uses the original tokenizer, output truncation, invisible characters, or garbled text may occur. During validation, ensure the following files are from the same version as the model: tokenizer.json, tokenizer_config.json, special_tokens_map.json, the vocabulary file, and the added_tokens configuration. The IDs for eos_token and pad_token must be consistent with the model configuration.
Validation can be completed in three steps. First, load the tokenizer and check if the vocabulary size matches the number of rows in the model’s embedding layer. Second, encode and then decode a set of samples containing Chinese, English, punctuation, code, and special tokens to confirm the result matches the original text. Third, generate a piece of text using the inference framework to check if the model stops outputting at the expected position.
Tool calling also requires validation. The fine-tuning data should include structured function call samples, with the output format fixed as parseable JSON. After deployment, use a set of test cases containing missing parameters, type errors, and no-tool-needed scenarios to check the model’s behavior, tracking the JSON parsing success rate and parameter accuracy. If parsing fails, the business system should refuse execution rather than directly calling the external interface.
4. Troubleshooting and Optimizing Multi-Turn Dialogue Stability
Garbled text, repetition, or semantic breaks in multi-turn dialogues usually stem from three types of causes.
First, the KV Cache exceeds the context window. As dialogue rounds increase, historical tokens continuously accumulate. The inference framework should set a clear context limit, and when exceeded, discard or compress history according to a defined strategy. If the truncation logic is flawed, it may cause abnormal attention calculation. It is recommended to log the token count of the input for each turn to easily locate the round where the problem occurs.
Second, inappropriate repetition penalty parameters. In long text generation, models are prone to falling into sub-word loops. A repetition_penalty that is too high will make the text stiff and incoherent, while too low will easily cause loops. A temperature that is too high increases randomness, while too low reduces output diversity. During parameter tuning, a grid search can be performed within the following ranges: repetition_penalty from 1.0 to 1.2 with a step of 0.05; temperature from 0.3 to 0.9 with a step of 0.1. Evaluation metrics include repetition rate (proportion of repeated n-grams), business task accuracy, and manual spot-check scores. Stop the search when the metrics show no significant improvement for two consecutive parameter groups. Save the current optimal configuration and record the version number for easy rollback.
Third, truncation leading to semantic fragmentation. Brutally truncating history by token length may cut off part of the System Prompt or Few-shot examples. A more robust approach is to truncate by complete dialogue turns, always retaining the system instructions and the most recent few turns. When history is too long, summaries can replace early dialogues, but the summaries themselves also require spot-checking.
5. Conclusion
The deployment of mid-sized models cannot simply be understood as “download and run.” From compliance alignment fine-tuning and quantized deployment to tokenizer and tool-calling validation, and further to multi-turn dialogue stability tuning, every step requires reproducible measurement and checking.
Before deployment, clarify the VRAM budget, framework version, and model license, and then sequentially complete baseline testing, false refusal and harmful request assessment, tokenizer consistency checking, and long-dialogue stress testing. After launch, continuously monitor the error rate and refusal rate, and roll back promptly if anomalies are detected.
Security and compliance are the prerequisites for model services. Business-side content review, access control, and log retention should be built synchronously with model capabilities so that localized LLM services can run stably and controllably.
