geneflowdecoder 0.1.2__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: geneflowdecoder
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: Gene Transformer + Conditional Rectified Flow decoder from cell-state z to log1p expression X.
5
5
  Author: GeneFlowDecoder Contributors
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "geneflowdecoder"
3
- version = "0.1.2"
3
+ version = "0.1.4"
4
4
  description = "Gene Transformer + Conditional Rectified Flow decoder from cell-state z to log1p expression X."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.9"
@@ -388,15 +388,25 @@ class GeneFlowDecoder(nn.Module):
388
388
  z = z.detach()
389
389
  return z.clone() if snapshot else z
390
390
 
391
- def _velocity(
392
- self, x_t: torch.Tensor, t: torch.Tensor, z: torch.Tensor
393
- ) -> torch.Tensor:
394
- z = self._maybe_detach(z)
395
- B = x_t.shape[0]
396
- t_emb = self.time_mlp(self._sincos(t)).unsqueeze(1)
397
- gids = self._gene_ids.unsqueeze(0).expand(B, -1)
398
- h = self.backbone(gids, z) + t_emb
399
- return self.vel_proj(h)
391
+ def _velocity(self, x_t: torch.Tensor, t: torch.Tensor,
392
+ z: torch.Tensor) -> torch.Tensor:
393
+ if self.freeze_z:
394
+ z = z.detach()
395
+ B, G = x_t.shape
396
+ t_emb = self.time_mlp(self._sincos(t)).unsqueeze(1) # [B,1,d]
397
+ gids = self._gene_ids[:G].unsqueeze(0).expand(B, -1) # [B,G]
398
+ h = self.backbone(gids, z) + t_emb # [B,G,d]
399
+
400
+ # ★ 关键:只对特征维 d 做线性,结果天然是 [B, G]
401
+ v = self.vel_proj(h.squeeze(-2) if h.ndim == 2 else h) # [B,G,d]→[B,G]
402
+ if v.ndim == 3:
403
+ v = v.squeeze(-1) # [B,G,1]→[B,G]
404
+ if v.ndim != 2 or v.shape != (B, G):
405
+ raise RuntimeError(
406
+ f"_velocity shape bug: got {tuple(v.shape)}, expected ({B},{G}). "
407
+ f"检查 vel_proj 是否为 nn.Linear(d, 1) 而非 nn.Linear(d, n_genes)"
408
+ )
409
+ return v
400
410
 
401
411
  # ----------------------------------------------------------------
402
412
  # objective
@@ -1,2 +1,2 @@
1
1
  # -*- coding: utf-8 -*-
2
- __version__ = "0.1.2"
2
+ __version__ = "0.1.4"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: geneflowdecoder
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: Gene Transformer + Conditional Rectified Flow decoder from cell-state z to log1p expression X.
5
5
  Author: GeneFlowDecoder Contributors
6
6
  License: MIT
File without changes