Deploying and Fine-Tuning Large Language Models On-Premises: A Practical Guide for Data-Sensitive Public Health Agencies

    This article walks through a practical approach to deploying and fine-tuning large language models (LLMs) inside an isolated internal network, using minimal accelerator hardware. It covers the dual constraints of data boundaries and compute cost, a five-layer architecture that separates the control plane from the data plane, cost-reduction techniques such as parameter-efficient fine-tuning, memory offloading to flash-based expansion, and quantized inference. It also details the data engineering workflow for specialized public health corpora, retrieval-augmented generation, security and auditability requirements, and an evaluation and rollout plan. Readers will find architecture guidance, illustrative pseudocode, and a sample instruction-tuning record they can adapt for other data-sensitive domains.

    1. Background: Two Constraints in Data-Sensitive Scenarios

    As the “AI Plus” initiative advances, demand for large language models in public health has shifted from “can we use it” to “how do we use it in a compliant way.” Disease control centers accumulate large volumes of data on infectious disease surveillance, immunization programs, chronic disease follow-ups, and laboratory test results. Many of these fields involve citizens’ health privacy and, by regulation, must not be moved to the public cloud or transferred across borders. This is the first constraint: the data boundary.

    The second constraint is compute cost. Mainstream LLM parameter counts range from a few billion to tens of billions. Conventional full-parameter fine-tuning typically requires 8 to 16 high-end accelerator cards, with hardware investment reaching millions of yuan, plus ongoing costs for power, cooling, and operations in the data center. For a prefecture-level agency, both the one-time capital expenditure and the long-term operational capacity are difficult to sustain.

    The real goal of such a project, therefore, is not to “pile up compute,” but to run a closed loop of deployment, fine-tuning, inference, and auditing inside an isolated internal network with as few accelerators as possible.

    2. Overall Architecture: A Layered Training and Inference Design

    A deployable on-premises solution is usually organized into five layers:

    1. Hardware layer: a small number of general-purpose GPUs combined with domestic or general AI accelerators, forming a heterogeneous compute pool.
    2. Memory expansion layer: middleware virtualizes an enterprise-grade flash pool into addressable expansion memory for the accelerators, used to swap model weights and the KV cache in and out.
    3. Model layer: a base model plus domain-adapted weights produced by parameter-efficient fine-tuning.
    4. Application layer: knowledge retrieval, intent recognition, report generation, question answering, and ticket routing.
    5. Security and operations layer: identity authentication, least-privilege access control, access auditing, encrypted transport and encryption at rest, logging, and monitoring with alerting.

    The key design principle is separation of the control plane from the data plane: the control plane handles scheduling and policy, while the data plane stays entirely within the internal network so that no data leaves the domain.

    3. Compute Economics: Why “Few Cards Plus Expansion Memory” Works

    Memory usage for conventional full-parameter fine-tuning can be roughly estimated as the sum of weights, gradients, and optimizer states, on the order of several times the parameter count. With 16-bit mixed precision and common optimizers, the empirical range is about 6 to 8 times. This makes memory capacity a hard threshold.

    Three cost-reduction paths:

    • Parameter-efficient fine-tuning: train only low-rank adapter matrices or prompt vectors, which typically reduces trainable parameters to a few thousandths of the total and sharply lowers memory demand.
    • Memory offloading and expansion: push inactive weight shards and optimizer states down to the flash expansion layer, swapping them in on demand.
    • Quantized inference: use 8-bit or lower-bit quantization during inference to increase throughput within an acceptable accuracy loss.

    Illustrative pseudocode (flow only, not a specific API):

    1. # 1) Load the quantized base model; weight shards can be offloaded to expansion memory
    2. model = load_base_model(quant="int8", offload_target="flash_pool")
    3. # 2) Inject low-rank adapters and freeze the backbone parameters
    4. model = inject_adapters(model, rank=16, alpha=32, dropout=0.05)
    5. # 3) Optimize only the adapter parameters
    6. trainable = [p for p in model.parameters() if p.requires_grad]
    7. optimizer = build_optimizer(trainable, lr=1e-4, warmup_ratio=0.03)
    8. # 4) Training loop (illustrative)
    9. for batch in domain_dataloader:
    10. loss = model.compute_loss(batch)
    11. loss.backward()
    12. optimizer.step()
    13. optimizer.zero_grad()

    4. Data Engineering for Domain Fine-Tuning

    Public health corpora have three characteristics: dense terminology, mixed structure, and scarce annotations. Data engineering should take priority over model selection.

    • Corpus layering: guidelines and standards (authoritative but slow to update), in-house knowledge bases (highly structured), de-identified medical records and follow-up notes (noisy), and Q&A tickets (close to real user phrasing).
    • Cleaning and de-identification: apply entity recognition and substitution to names, ID numbers, contact details, and addresses while preserving clinical semantics.
    • Instruction construction: convert high-frequency tasks such as “explaining statistical definitions,” “extracting report highlights,” and “generating follow-up scripts” into instruction-response pairs.
    • Quality validation: dual-person sampling checks plus rule-based validation (for example, dosage, units, and time ranges), with traceable data versioning.

    A minimal usable instruction sample structure:

    1. {
    2. "instruction": "Based on the following surveillance data highlights, write a brief summary for grassroots agencies, avoiding absolute statements.",
    3. "input": "The number of newly reported cases this week increased compared with the previous week, concentrated mainly in two age groups...",
    4. "output": "Reported cases show an upward trend this week. Strengthening surveillance of key populations and health education is recommended...",
    5. "meta": {"source": "de-identified ticket", "review": "passed"}
    6. }

    5. Retrieval Augmentation: Moving “Memory” to an Updatable Knowledge Base

    Fine-tuning is good at changing expression style and task patterns, but poor at holding frequently updated facts. Placing knowledge in a vector retrieval store can significantly reduce the fine-tuning burden:

    • Document chunking: split by clauses and subsections, keeping heading hierarchy as metadata.
    • Hybrid retrieval: combine keyword search with semantic search to improve recall of proper nouns.
    • Reranking and citation: rerank candidate passages and annotate source clauses in answers to support human review.
    • Fallback strategy: when retrieval confidence is low, explicitly refuse to answer or hand off to a human, avoiding fabrication.

    6. Security, Compliance, and Auditability

    • Network isolation: the full stack is deployed on the agency’s internal network, physically or logically isolated from the internet.
    • Identity and permissions: role-based least privilege, separating model management, data import, and inference invocation.
    • Encryption and auditing: encrypt data in transit and at rest, and record the complete chain of “who did what with which data and when.”
    • Data lifecycle: define policies for collection, use, retention, and destruction; export actions require approval.

    7. Evaluation, Launch, and Operations

    Evaluation should cover three categories of metrics: task effectiveness (summary completeness, factual consistency), security and compliance (sensitive information leakage rate, refusal rate for unauthorized requests), and engineering performance (time to first token, throughput, and hit rates for memory and expansion memory). Rollout should be gradual: internal trial first, then a small-scale pilot, then broader release.

    The operations focus is observability: collect logs, metrics, and traces in a unified way, and set capacity and anomaly alerts. For the expansion memory layer in particular, monitor swap-in and swap-out frequency to avoid jitter that degrades latency.

    8. Conclusion

    Without data leaving the domain, public health agencies can build a small-scale, cost-controlled, secure, and auditable private AI foundation by combining a few accelerators, flash-based expansion, parameter-efficient fine-tuning, and retrieval augmentation. This path has been validated at multiple prefecture-level agencies. Further work can optimize scheduling policies, broaden hardware compatibility, and accumulate reusable data and evaluation standards, offering a reference model for other data-sensitive industries.