Skip to content

fix: harden PositionGetter device cache, headless vis imports, GLB skyseg parity, and Unicode/glob paths - #120

Open
mlubbad wants to merge 1 commit into
Robbyant:mainfrom
mlubbad:fix/cache-device-headless-vis-and-unicode-paths
Open

mlubbad wants to merge 1 commit into
Robbyant:mainfrom
mlubbad:fix/cache-device-headless-vis-and-unicode-paths

Conversation

@mlubbad

@mlubbad mlubbad commented Nov 21, 2026

Copy link
Copy Markdown

Summary

Fixes five subtle cross-device, headless-import, GLB-export, and filesystem bugs noticed while running lingbot-map in headless batch and multi-device workflows:

  1. PositionGetter cross-device cache collision (lingbot_map/layers/rope.py): PositionGetter.position_cache keyed only on (height, width) (unlike RotaryPositionEmbedding2D._compute_frequency_components, which includes device and dtype). Calling PositionGetter on CPU (e.g. during tests or preprocessing) and then on CUDA/MPS returned cached CPU index tensors and raised a cross-device RuntimeError inside F.embedding(positions, cos_comp).
  2. Headless lingbot_map.vis import without optional [vis] extra (lingbot_map/vis/__init__.py): demo_render/batch_demo.py and headless scripts import lingbot_map.vis.sky_segmentation / lingbot_map.vis.glb_export, which triggered lingbot_map/vis/__init__.py and unconditionally imported viser (PointCloudViewer), raising ModuleNotFoundError: No module named 'viser' on base installs without .[vis]. Guarded PointCloudViewer and viser_wrapper as optional imports.
  3. glb_export.py duplicate run_skyseg / segment_sky divergence + degenerate scene_scale (lingbot_map/vis/glb_export.py):
    • glb_export.run_skyseg reshaped inputs to (-1, 3, input_size[0], input_size[1]) ((W, H) transposed vs sky_segmentation.run_skyseg's (H, W)) and divided by (max_value - min_value) without an epsilon guard (emitting NaN warnings on uniform frames).
    • glb_export.segment_sky called os.makedirs(os.path.dirname(mask_filename), exist_ok=True) without guarding bare filenames (dirname == "" -> FileNotFoundError) or image is None.
    • Delegated both helpers to the canonical implementations in lingbot_map.vis.sky_segmentation, and clamped scene_scale >= 1e-3 in predictions_to_glb so degenerate/coincident point clouds do not pass zero radius/height to trimesh.creation.cone.
  4. Glob metacharacters, image_folder="." cache naming, and non-ASCII image paths (lingbot_map/vis/sky_segmentation.py):
    • Escaped image_folder with glob.escape(...) in _list_image_files so folder names containing literal [...] (e.g. scan_[2026]) are not interpreted as character classes.
    • Normalized default sky_mask_dir via os.path.abspath(image_folder).rstrip("/\\") + "_sky_masks" so image_folder="." does not write to a hidden ._sky_masks directory.
    • Used np.fromfile + cv2.imdecode / cv2.imencode + .tofile so non-ASCII/Unicode paths work reliably across platforms.
  5. Exception-safe _set_skip_append(False) reset (gct_stream.py, gct_stream_window.py, gct_stream_window_v2.py): Wrapped non-keyframe self.forward(...) calls in try ... finally so a transient runtime error on a non-keyframe cannot leave _skip_append=True stuck on the KV cache.

Testing

  • Added tests/test_cache_vis_and_path_safety.py covering all 6 cases (pytest -v tests/test_cache_vis_and_path_safety.py: 6 passed).
  • Checked against open PRs (#82, #85, #88, #115, #116) to avoid overlapping hunks.

… and path safety

Signed-off-by: Dr. Mohammed Lubbad <engmlubbad@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant