abtonmoy commited on
Commit
4bad8f3
·
verified ·
1 Parent(s): 71170e9

inference.py: gate guard on embed_image (non-audio inputs must run with the gate closed)

Browse files
Files changed (1) hide show
  1. inference.py +7 -0
inference.py CHANGED
@@ -157,6 +157,13 @@ class FusionEmbedder:
157
  @torch.no_grad()
158
  def embed_image(self, image, dim: Optional[int] = None) -> torch.Tensor:
159
  from PIL import Image
 
 
 
 
 
 
 
160
  if isinstance(image, (str, os.PathLike)):
161
  image = Image.open(str(image))
162
  image = image.convert("RGB")
 
157
  @torch.no_grad()
158
  def embed_image(self, image, dim: Optional[int] = None) -> torch.Tensor:
159
  from PIL import Image
160
+ gate = getattr(self.model, "_adapter_gate", None)
161
+ if gate is not None and gate.active:
162
+ # The vision path runs through the same (hook-carrying) decoder layers;
163
+ # non-audio inputs must execute with the gate closed so the adapter
164
+ # branch never runs. Mirrors the encode_text guard.
165
+ raise RuntimeError("adapter gate is open during an image embed — "
166
+ "non-audio inputs must run with the gate closed")
167
  if isinstance(image, (str, os.PathLike)):
168
  image = Image.open(str(image))
169
  image = image.convert("RGB")