- GLM Legal setup covers environment prep, dependency installation, and model loading for law-glm-10b
- Hardware matters: the 10B model requires roughly 39.5 GB of storage and substantial GPU memory
- trust_remote_code is required: loading the model executes custom code, so verify the source first
- Two variants exist: law-glm-10b and law-glm-10b-v2, both hosted under the law-llm Hugging Face organization
- License is Apache-2.0: suitable for research and many commercial uses, but verify conditions before deployment
GLM Legal Setup Overview: What You Need Before Starting
Setting up GLM Legal locally is a straightforward process if you prepare the right environment first. GLM Legal refers to the GLM-architecture legal-domain models published under the law-llm organization on Hugging Face, principally law-glm-10b and law-glm-10b-v2. Both model pages are publicly accessible and tagged with the Apache-2.0 license.
The setup process differs from a typical small-model workflow in three ways: the parameter scale (10B) demands serious hardware planning, the model files total approximately 39.5 GB, and loading requires the trust_remote_code flag because the model relies on custom modeling code.
Model Basics
- 10B parameters, GLM architecture
- Two variants: base and v2
- Legal-domain fine-tuning for Chinese legal text
Storage Needs
- ~39.5 GB model file size
- SSD strongly recommended
- Additional space for datasets and caches
Software Stack
- Python 3.8+
- PyTorch with CUDA support
- Hugging Face Transformers
Confirm you have at least 60 GB of free disk space before starting. The 39.5 GB model download plus Hugging Face cache duplication can consume more space than expected.
The table below summarizes the core facts you should verify before setup:
| Item | Detail | Notes |
|---|---|---|
| Model page | law-llm/law-glm-10b | Public on Hugging Face |
| Variant | law-glm-10b-v2 | Updated release, same org |
| Parameters | 10B | Requires high-VRAM GPU |
| File size | ~39.5 GB | Plan SSD storage |
| License | Apache-2.0 | Listed on model page |
| Upstream code | THUDM/GLM | Architecture reference |
Hardware and Software Requirements
GLM Legal setup succeeds or fails at the hardware planning stage. A 10B-parameter model in full precision does not fit on consumer GPUs without quantization, so match your deployment strategy to your available resources.
| Configuration | GPU Memory | Method | Best For |
|---|---|---|---|
| Full precision | 40+ GB | A100 / multi-GPU | Research, fine-tuning |
| Half precision (fp16) | ~20-24 GB | High-end consumer/pro cards | Standard inference |
| Quantized (INT8/4-bit) | ~10-14 GB | bitsandbytes / GPTQ | Budget local setups |
| CPU only | N/A | Very slow inference | Testing only, not practical |
On the software side, you need a Python environment with PyTorch built for your CUDA version, the Transformers library, and the standard Hugging Face tooling (huggingface_hub, tokenizers, accelerate for device management).
Do not attempt full-precision loading on GPUs with less than 40 GB of VRAM. Use half precision or quantization instead, or the load will fail with an out-of-memory error after a long download.
Verify your environment before downloading the model. A quick checklist:
Pre-Setup Environment Checklist:
- Python 3.8 or newer installed
- CUDA-capable GPU with current drivers
- PyTorch installed with CUDA support
- At least 60 GB free SSD storage
- Stable internet connection for 39.5 GB download
Step-by-Step GLM Legal Installation
Follow this sequence to go from a clean machine to a working inference environment. Each step builds on the previous one, so do not skip ahead.
Create an isolated environment
Set up a dedicated virtual environment using venv or conda so GLM Legal dependencies do not conflict with other projects. Activate it before installing anything.
Install PyTorch with CUDA
Install the PyTorch build matching your CUDA version from the official PyTorch index. Confirm GPU visibility with a quick tensor-to-CUDA test before continuing.
Install Transformers and dependencies
Install the Hugging Face Transformers library along with accelerate and huggingface_hub. These handle model downloading, device placement, and tokenizer loading.
Download the model weights
Pull law-glm-10b or law-glm-10b-v2 from the Hugging Face model page. The full set of files totals roughly 39.5 GB, so run the download in a stable session or use resumable transfer.
Load with trust_remote_code
Load the model and tokenizer with trust_remote_code=True. GLM Legal ships custom modeling code that Transformers executes at load time, and loading fails without this flag.
Run a first inference test
Feed a short Chinese legal question or clause-extraction prompt, verify the output shape and coherence, and record baseline generation settings for later tuning.
Use a Hugging Face access token and enable transfer resumption when downloading. A failed 39.5 GB download without resume support wastes hours.
trust_remote_code: What It Does and How to Stay Safe
The trust_remote_code parameter is the single most misunderstood part of GLM Legal setup. Because GLM Legal's architecture includes custom Python code hosted with the model repository, Transformers must download and execute that code when loading the model. The flag is your explicit consent to this behavior.
| Aspect | What Happens | Recommended Practice |
|---|---|---|
| Load behavior | Custom modeling code runs locally | Read the repo code before first load |
| Source control | Code comes from law-llm org | Pin the revision you reviewed |
| Repeat runs | Code cached after first download | Re-verify after updates |
| Sharing envs | Code runs with your permissions | Use isolated environments |
Never set trust_remote_code=True on unverified or mirrored repositories. Review the repository files on the official law-llm model pages, and pin a specific commit revision in production so the executed code cannot silently change.
For teams deploying GLM Legal in shared infrastructure, sandbox the loading environment, log the revision hash used, and document the review in your deployment record. This turns a security question into a routine procedural step.
Inference Configuration and Legal Prompting
Once GLM Legal setup is complete, the quality of output depends heavily on how you structure inputs. Legal tasks reward explicit prompts that separate facts, task objectives, jurisdiction, and output format.
Legal QA
- State the jurisdiction explicitly
- Supply the relevant legal text
- Ask for cited conclusions only
Clause Extraction
- Define the output schema up front
- Require clause-level citations
- Flag ambiguous language separately
Document Summarization
- Limit scope to supplied materials
- Request structured sections
- Ask for an uncertainty note
A comparison of common generation settings for legal workloads:
| Setting | Conservative | Balanced | Fast Drafting |
|---|---|---|---|
| Temperature | 0.1-0.3 | 0.5 | 0.7 |
| Top-p | 0.9 | 0.92 | 0.95 |
| Use case | Citation-adjacent QA | Summaries | Brainstorm drafts |
| Review need | Still required | Required | Heavier review |
Low temperature reduces but does not eliminate hallucinated citations. Every legal authority, date, party name, and quotation produced by the model must be verified against original sources before any professional use.
FAQ
Q: What is GLM Legal setup, and who is it for?
GLM Legal setup is the process of preparing an environment to run law-glm-10b or law-glm-10b-v2 locally: installing Python, PyTorch, and Transformers, downloading the roughly 39.5 GB weights, and loading the model with trust_remote_code. It is aimed at researchers and developers working on Chinese legal text tasks.
Q: Can I run GLM Legal on a consumer GPU?
Full-precision loading of a 10B model generally requires around 40 GB of VRAM. With half precision or quantization, capable consumer cards in the 12-24 GB range can run inference, though with some speed and quality trade-offs. CPU-only inference is technically possible but impractically slow.
Q: Why does loading fail without trust_remote_code?
GLM Legal repositories include custom modeling code that Transformers must execute to build the model. Setting trust_remote_code=True grants that permission. Always review the repository code and pin a revision before enabling it.
Q: What license applies to GLM Legal, and can I use it commercially?
The model pages list Apache-2.0, a permissive license that allows commercial use in many scenarios. You should still verify the model page terms, attribute appropriately, and note that license compliance does not replace legal review of outputs used in professional practice.