diff --git a/data_only_viz/apple_vision_pose.py b/data_only_viz/apple_vision_pose.py index a8431a4..2ccb3f5 100644 --- a/data_only_viz/apple_vision_pose.py +++ b/data_only_viz/apple_vision_pose.py @@ -557,10 +557,8 @@ class AppleVisionPoseWorker: # API d'acces simple. Face parsing depuis Apple Vision est # actuellement bloque ; on garde MediaPipe (CPU XNNPACK) pour # face/hand fin tandis que Vision sert body 2D sur ANE. - n = 0; n_written = 0 - if n_written > 0 and not hasattr(self, "_logged_face_write_" + region_name): - LOG.info("face: %s wrote %d points", region_name, n_written) - setattr(self, "_logged_face_write_" + region_name, True) + # Skip pour eviter le spam ObjCPointerWarning a 30 fps. + return # faceContour fill("faceContour", *FACE_OFFSETS["contour"]) diff --git a/data_only_viz/multi_hmr_worker.py b/data_only_viz/multi_hmr_worker.py index a09092a..916d703 100644 --- a/data_only_viz/multi_hmr_worker.py +++ b/data_only_viz/multi_hmr_worker.py @@ -142,6 +142,20 @@ class MultiHMRWorker: model = Model(**kwargs).to(torch_device) model.load_state_dict(ckpt["model_state_dict"], strict=False) model.eval() + # MPS mixed precision via torch.autocast : ~1.3-1.7x sur + # ViT-S backbone, casts auto vers float16 pour les matmuls + # gardant l'accumulator en float32 (necessaire MPS sinon + # "Destination NDArray and Accumulator NDArray cannot have + # different datatype" sur MPSNDArrayMatrixMultiplication). + # Disable via env MULTIHMR_AUTOCAST=0. + # autocast MPS teste 2026-05-13 : plus lent (400ms vs 270ms + # baseline) car overhead de cast dans le forward. Defaut OFF. + # Opt-in via MULTIHMR_AUTOCAST=1. + self._use_autocast = ( + device == "mps" + and os.environ.get("MULTIHMR_AUTOCAST", "0") == "1") + if self._use_autocast: + LOG.info("Multi-HMR PyTorch : MPS autocast (fp16) enabled") # torch.compile teste 2026-05-13 : plante en runtime avec # `TypeError: torch.Size() takes an iterable of 'int' (item # is 'FakeTensor')`. Multi-HMR a du shape-arithmetic non @@ -230,13 +244,24 @@ class MultiHMRWorker: t_inf_start = time.monotonic() try: with torch.no_grad(): - humans = model( - tensor, - is_training=False, - nms_kernel_size=self.nms_kernel_size, - det_thresh=self.det_thresh, - K=K, - ) + if getattr(self, "_use_autocast", False): + with torch.autocast(device_type="mps", + dtype=torch.float16): + humans = model( + tensor, + is_training=False, + nms_kernel_size=self.nms_kernel_size, + det_thresh=self.det_thresh, + K=K, + ) + else: + humans = model( + tensor, + is_training=False, + nms_kernel_size=self.nms_kernel_size, + det_thresh=self.det_thresh, + K=K, + ) except Exception as e: LOG.warning("inference failed: %s", e) time.sleep(self.period)