Skip to content

Tutorial: OCADR HF inference

In this tutorial you will run ll_ocadr’s HF-native pipeline: encode a 3D object’s geometry into a language model’s embedding space and have the model describe it. Allow ~15 minutes (first run downloads the chosen LM).

The <mesh> placeholder in the prompt marks where the encoded geometry tokens go.

Terminal window
python ll_ocadr/run_ll_ocadr_hf.py \
--model Qwen/Qwen2-1.8B \
--mesh part.stl \
--prompt "Describe this CAD part: <mesh>" \
--max-new-tokens 64
  • --model is any HF causal LM; n_embed is derived from it automatically.
  • --mesh accepts a mesh (STL/OBJ/PLY) or a STEP file (STEP needs pythonocc-core).
  • --no-cropping uses the global view only; otherwise the object is chunked into local tiles plus a global view.
from ll_ocadr.run_ll_ocadr_hf import build_model_and_tokenizer, run_inference
model, tokenizer, config, processor = build_model_and_tokenizer("Qwen/Qwen2-1.8B")
text = run_inference(model, processor, tokenizer, "part.stl", "Describe <mesh>")
print(text)

build_model_and_tokenizer constructs LatticelabsOCADRForCausalLM, registers the <mesh> token, and resizes the LM embeddings. run_inference chunks the geometry, encodes it (GeometryNet PointNet++ local + ShapeNet ViT global → MLP projector), splices the geometry embeddings into the prompt, and calls the LM’s generate.

The fast tests exercise the encoders and chunkers with no model download; the slow tests run an end-to-end forward/generate on a tiny offline LM.

Terminal window
cd ll_ocadr
pytest tests/ -m "not slow" # encoders, chunkers, fixtures
pytest tests/ -m slow # e2e + CLI on a tiny offline LM