This is a submission for DEV's Summer Bug Smash: Clear the Lineup powered by Sentry.
Project Overview
CODA OS is a fully local AI ecosystem — 228K+ lines of code, custom 2.2B transformer, 3D body reconstruction from phone videos, voice assistant, video calling, messaging. Zero cloud dependency.
The specific repos I fixed:
- rotation-scan-3d — CPU-only 3D body reconstruction from phone rotation videos
- coda-forge-3d — 18-stage photorealistic 3D reconstruction pipeline
- bhaasm-transformer — Custom decoder-only transformer with MoE, GQA, RoPE
Bug Fix or Performance Improvement
Three issues across three repos:
1. Texture bug in GLB export (coda-forge-3d)
The _export_textured_glb method accepted a texture_path parameter but never used it. The texture was hardcoded to None, so every textured GLB export lost its texture. This meant users calling export_all(mesh_path, texture_path="texture.png") would get a GLB without any texture applied.
2. Tokenizer loaded 256 times per generation (bhaasm-transformer)
The _tokenize and _detokenize functions in sampler.py each independently loaded the BPE tokenizer from disk on every single call. During generation with max_new_tokens=256, this meant 256+ file reads and tokenizer initializations. The tokenizer was never cached.
3. Redundant computation (rotation-scan-3d)
In pipeline_adapter.py, estimate_body_volume() was called twice in succession — once without weight_kg (result discarded) and once with weight_kg. The first call was wasted computation that did nothing.
Code
Fix 1: Texture bug — coda-forge-3d/src/codaforge/export/export_manager.py
# Before (broken):
def _export_textured_glb(self, mesh, texture_path, path):
material = trimesh.visual.material.PBRMaterial(
baseColorTexture=None, # <-- BUG: texture ignored
baseColorFactor=[1.0, 1.0, 1.0, 1.0],
)
if mesh.visual.kind == "texture":
mesh.visual.material = material
mesh.export(path, file_type="glb")
# After (fixed):
def _export_textured_glb(self, mesh, texture_path, path):
import PIL.Image as PILImage
img = PILImage.open(texture_path)
material = trimesh.visual.material.PBRMaterial(
baseColorTexture=img, # <-- Now actually uses the texture
baseColorFactor=[1.0, 1.0, 1.0, 1.0],
)
mesh.visual.material = material
mesh.export(path, file_type="glb")
Fix 2: Tokenizer caching — bhaasm-transformer/src/bhaasm/inference/sampler.py
# Before (slow):
def _tokenize(text, vocab_size):
try:
tok_path = Path("data/bpe_tokenizer.json")
if tok_path.exists():
tok = load_tokenizer(str(tok_path)) # Loaded every call
return tok.encode(text)
except Exception:
pass
return [min(ord(c), vocab_size - 1) for c in text] + [0]
# After (fast):
from functools import lru_cache
@lru_cache(maxsize=1)
def _get_tokenizer(tokenizer_path="data/bpe_tokenizer.json"):
tok_path = Path(tokenizer_path)
if tok_path.exists():
return load_tokenizer(str(tok_path))
return None
def _tokenize(text, vocab_size):
tok = _get_tokenizer()
if tok is not None:
return tok.encode(text)
return [min(ord(c), vocab_size - 1) for c in text] + [0]
Fix 3: Redundant call — rotation-scan-3d/src/rotationscan/pipeline_adapter.py
# Before (wasted):
if weight_kg is not None and weight_kg > 0:
estimate_body_volume(ellipse_params, lengths_cm) # Result discarded
estimate_body_volume(ellipse_params, lengths_cm, weight_kg=weight_kg)
# After (clean):
if weight_kg is not None and weight_kg > 0:
estimate_body_volume(ellipse_params, lengths_cm, weight_kg=weight_kg)
My Improvements
Texture fix: The bug was subtle — the method signature accepted texture_path and the caller checked if texture_path and os.path.isfile(texture_path) before calling it, so it looked like it should work. But inside the method, baseColorTexture=None meant the texture was silently dropped. The fix loads the image with PIL and passes it to PBRMaterial. Also added error handling around trimesh.load in the parent export_all method.
Tokenizer performance: The old code loaded the tokenizer from disk on every _tokenize and _detokenize call. During a 256-token generation, that's 512+ file reads. Using functools.lru_cache(maxsize=1) caches the tokenizer object after the first load. Same tokenizer, zero re-reads. The _detokenize function was also updated to use the cached tokenizer instead of independently loading its own copy.
Redundant computation: The first estimate_body_volume call computed uncalibrated volume but discarded the result. The second call recomputed with weight calibration. Removing the first call eliminates unnecessary work without changing behavior — the calibrated result is identical.
All three fixes are committed and CI-passing across Python 3.10, 3.11, and 3.12.
Best Use of Sentry
Not submitting to this category.
Top comments (0)