Skip to content
Back to skills

Chat And Demos

ASecurity

"Guides ChatGLM2-6B local generation, streaming chat, CLI and

  • 247 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 8, 2026
toolspythonrustapibackend

Works with

  • terminal
  • cli
  • api

Security analysis

A100/100

Pro scans all 8 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add VectorSpaceLab/AREX-Skill --skill chat-and-demos --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Chat And Demos?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Chat And Demos
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectorspacelab-chat-and-demos/badge)](https://www.skillsdirectory.com/skills/vectorspacelab-chat-and-demos)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: chat-and-demos
description: "Guides ChatGLM2-6B local generation, streaming chat, CLI and
  Gradio/Streamlit demos, quantization, CPU/MPS fallback, and multi-GPU
  placement."
disable-model-invocation: true
metadata:
  disco-role: operating
license: NOASSERTION
---

# ChatGLM2-6B Chat and Demos

Use this route when the task asks to load ChatGLM2-6B locally, generate a
response, preserve conversation history, run the terminal/Gradio/Streamlit
examples, use quantization, or split a model across GPUs. Use
[`api-serving`](../api-serving/SKILL.md) for HTTP endpoints, [`ptuning`](../ptuning/SKILL.md)
for tuned checkpoints, and [`evaluation`](../evaluation/SKILL.md) for C-Eval.

## First decisions

1. Identify the model source: a Hub id such as `THUDM/chatglm2-6b`, a pinned
   Hub revision such as `v1.0`, or a complete local model directory. Model
   weights are not bundled with this skill.
2. Choose the backend before writing a command. The repository's official
   demos call `.cuda()`. CPU inference is slower and memory-heavy; Mac MPS
   requires a local model path and a compatible PyTorch build.
3. Check memory, model variant, and context limits. FP16/BF16 is documented as
   roughly 13 GB; INT4 reduces the reported minimum to about 5–6 GB but uses
   quantization kernels and can change quality.
4. Run the bundled environment check before loading weights:
   `python sub-skills/chat-and-demos/scripts/check_chatglm2_environment.py --backend auto`.
5. For a multi-GPU plan, inspect the deterministic placement first:
   `python sub-skills/chat-and-demos/scripts/inspect_device_map.py --num-gpus 2`.

## Common loading shape

Use the Transformers remote-code contract and keep the model in evaluation
mode:

```python
from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained(
    MODEL_OR_PATH, trust_remote_code=True, revision=REVISION  # optional
)
model = AutoModel.from_pretrained(
    MODEL_OR_PATH, trust_remote_code=True, revision=REVISION  # optional
).eval()
```

For a normal CUDA model, move the model to CUDA after loading. For CPU use
`.float()` and expect much slower generation. For Apple MPS, load from a local
path and use `.to("mps")`; the repository documents this as a Mac-specific
path, not a Linux fallback.

The usual single-turn call is `model.chat(tokenizer, query, history=[])` and
returns `(response, history)`. For incremental output use
`model.stream_chat(...)`; pass the returned `history` into the next turn. The
CLI and web demos also retain `past_key_values` when the model implementation
supports it. Do not mix a prefix-tuned checkpoint with the base-model route;
use [`ptuning`](../ptuning/SKILL.md) for that distinction.

## Demo routing

- **CLI:** use the interactive loop only after model loading succeeds. Enter a
  prompt, `clear` to reset history, and `stop` to exit. This is a blocking
  interactive process, not a smoke test.
- **Gradio:** use the legacy-compatible dependency range documented in
  [`demo-workflows.md`](references/demo-workflows.md). The source calls the
  deprecated `.style()` method; recent Gradio 6 releases fail before launch.
- **Streamlit:** launch with `streamlit run` and keep model loading in the
  cached resource path. The sidebar controls `max_length`, `top_p`, and
  `temperature`; the session stores history and past key values.
- **Quantization:** use a model/checkpoint that supports the requested 4- or
  8-bit route. Do not claim that a CPU or MPS run supports CUDA-only INT4
  kernels; read the compatibility notes before choosing a device.
- **Multi-GPU:** call the bundled map inspector first. The repository's helper
  keeps embeddings, final layer norm, output layer, rotary positions, and
  `lm_head` on GPU 0, then distributes encoder layers. Use `accelerate` for
  dispatch and verify the actual map on the target model.

Read [`model-loading.md`](references/model-loading.md) for loading and device
choices, [`demo-workflows.md`](references/demo-workflows.md) for command
recipes, and [`troubleshooting.md`](references/troubleshooting.md) when a
model, backend, UI, or memory error appears. The bundled helpers are safe
preflight tools; they never download weights or start a server.

Files in this skill

  • SKILL.md4.1 KB
  • references/demo-workflows.md2.7 KB
  • references/model-loading.md3.5 KB
  • references/troubleshooting.md3.1 KB
  • scripts/check_chatglm2_environment.py4.1 KB
  • scripts/gradio_chat_demo.py4.8 KB
  • scripts/inspect_device_map.py2.1 KB
  • scripts/stream_chat_cli.py4.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.