bernardo-de-almeida commited on
Commit
a56975c
·
1 Parent(s): 7fad7e0

fix: pipeline

Browse files
Files changed (2) hide show
  1. app.py +3 -3
  2. ntv3_tracks_pipeline.py +13 -39
app.py CHANGED
@@ -26,7 +26,7 @@ matplotlib.use("Agg")
26
  # -----------------------------
27
  # Env / auth
28
  # -----------------------------
29
- MODEL_ID = os.environ.get("MODEL_ID", "InstaDeepAI/NTv3_650M_pos")
30
  DEFAULT_SPECIES = os.environ.get("DEFAULT_SPECIES", "human")
31
  HF_TOKEN = (
32
  os.environ.get("NTV3_HF_TOKEN")
@@ -887,8 +887,8 @@ with gr.Blocks(title="NTv3 Tracks Demo") as demo:
887
 
888
  # Model display names (without InstaDeepAI/ prefix) and their full IDs
889
  MODEL_OPTIONS = {
890
- "NTv3 650M (post)": "InstaDeepAI/NTv3_650M_pos",
891
- "NTv3 100M (post)": "InstaDeepAI/NTv3_100M_pos",
892
  }
893
 
894
  # Reverse mapping: full ID -> display name
 
26
  # -----------------------------
27
  # Env / auth
28
  # -----------------------------
29
+ MODEL_ID = os.environ.get("MODEL_ID", "InstaDeepAI/NTv3_650M_post")
30
  DEFAULT_SPECIES = os.environ.get("DEFAULT_SPECIES", "human")
31
  HF_TOKEN = (
32
  os.environ.get("NTV3_HF_TOKEN")
 
887
 
888
  # Model display names (without InstaDeepAI/ prefix) and their full IDs
889
  MODEL_OPTIONS = {
890
+ "NTv3 650M (post)": "InstaDeepAI/NTv3_650M_post",
891
+ "NTv3 100M (post)": "InstaDeepAI/NTv3_100M_post",
892
  }
893
 
894
  # Reverse mapping: full ID -> display name
ntv3_tracks_pipeline.py CHANGED
@@ -279,7 +279,7 @@ class NTv3TracksOutput:
279
  species: str | None = None
280
  assembly: str | None = None
281
  bigwig_track_names: list[str] | None = (
282
- None # from cfg.bigwigs_per_file_assembly[assembly]
283
  )
284
  bed_element_names: list[str] | None = None
285
  window_len: int | None = None
@@ -347,21 +347,6 @@ class NTv3TracksPipeline(Pipeline):
347
  self.config, "name_or_path", None
348
  )
349
 
350
- # Load species_tokenizer (following ntv3_gff_pipeline.py pattern)
351
- if self.model_id:
352
- self.species_tokenizer = AutoTokenizer.from_pretrained(
353
- self.model_id,
354
- subfolder="species_tokenizer",
355
- trust_remote_code=trust_remote_code,
356
- token=token,
357
- )
358
- else:
359
- self.species_tokenizer = kwargs.get("species_tokenizer", None)
360
- if self.species_tokenizer is None:
361
- raise ValueError(
362
- "Pass species_tokenizer=... when constructing with a model module."
363
- )
364
-
365
  # bed names (your notebooks refer to bed_element_names)
366
  self.bed_element_names = getattr(
367
  self.config, "bed_elements_names", None
@@ -380,20 +365,13 @@ class NTv3TracksPipeline(Pipeline):
380
  Return BigWig track IDs for the assembly corresponding to `species`.
381
  No model forward pass.
382
  """
383
- sp = species or self.default_species
384
- assembly = SPECIES_TO_ASSEMBLY.get(sp)
385
- if assembly is None:
386
  raise ValueError(
387
- f"Unknown species={sp}. Supported: {sorted(SPECIES_TO_ASSEMBLY.keys())}"
 
388
  )
389
 
390
- if assembly not in self.config.bigwigs_per_file_assembly:
391
- raise ValueError(
392
- f"Assembly {assembly} not found in checkpoint config. "
393
- f"Available: {list(self.config.bigwigs_per_file_assembly.keys())}"
394
- )
395
-
396
- return list(self.config.bigwigs_per_file_assembly[assembly])
397
 
398
  def available_bed_element_names(self) -> list[str]:
399
  """
@@ -416,12 +394,11 @@ class NTv3TracksPipeline(Pipeline):
416
  )
417
  assembly = SPECIES_TO_ASSEMBLY[species]
418
 
419
- cfg_assemblies = list(self.config.bigwigs_per_file_assembly.keys())
420
- if assembly not in cfg_assemblies:
421
  raise ValueError(
422
- f"Species '{species}' maps to assembly '{assembly}', "
423
- f"but that assembly is not available in this checkpoint. "
424
- f"Available assemblies: {cfg_assemblies}"
425
  )
426
  return species, assembly
427
 
@@ -478,17 +455,15 @@ class NTv3TracksPipeline(Pipeline):
478
  input_ids = input_ids_cpu.to(device)
479
  # Species tokenization - match batch size
480
  batch_size = input_ids.shape[0]
481
- species_ids = self.species_tokenizer(
482
- [species] * batch_size, add_special_tokens=False, return_tensors="pt"
483
- )
484
- species_ids_tensor = species_ids["input_ids"].to(device)
485
 
486
  # Prediction interval (not used for slicing logits, just x-axis)
487
  pred_start = start + int(window_len * self.pred_center_offset_fraction)
488
  pred_end = pred_start + int(window_len * self.pred_center_fraction)
489
 
490
  # ✅ The source of truth for track IDs/names (your note)
491
- bigwig_track_names = list(self.config.bigwigs_per_file_assembly[assembly])
492
 
493
  return {
494
  "input_ids": input_ids,
@@ -564,7 +539,6 @@ class NTv3TracksPipeline(Pipeline):
564
  out = self.model(
565
  input_ids=model_inputs["input_ids"],
566
  species_ids=model_inputs["species_ids"],
567
- return_dict=True,
568
  )
569
  out["meta"] = meta
570
  return out
@@ -589,7 +563,7 @@ class NTv3TracksPipeline(Pipeline):
589
  if out.bigwig_track_names is None:
590
  raise ValueError(
591
  "bigwig_track_names missing; expected "
592
- "cfg.bigwigs_per_file_assembly[assembly]."
593
  )
594
  if out.bed_element_names is None:
595
  raise ValueError("bed element names missing from config.")
 
279
  species: str | None = None
280
  assembly: str | None = None
281
  bigwig_track_names: list[str] | None = (
282
+ None # from cfg.bigwigs_per_species[species]
283
  )
284
  bed_element_names: list[str] | None = None
285
  window_len: int | None = None
 
347
  self.config, "name_or_path", None
348
  )
349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  # bed names (your notebooks refer to bed_element_names)
351
  self.bed_element_names = getattr(
352
  self.config, "bed_elements_names", None
 
365
  Return BigWig track IDs for the assembly corresponding to `species`.
366
  No model forward pass.
367
  """
368
+ if species not in self.config.bigwigs_per_species:
 
 
369
  raise ValueError(
370
+ f"Species {species} not found in checkpoint config. "
371
+ f"Available: {list(self.config.bigwigs_per_species.keys())}"
372
  )
373
 
374
+ return list(self.config.bigwigs_per_species[species])
 
 
 
 
 
 
375
 
376
  def available_bed_element_names(self) -> list[str]:
377
  """
 
394
  )
395
  assembly = SPECIES_TO_ASSEMBLY[species]
396
 
397
+ cfg_species = list(self.config.bigwigs_per_species.keys())
398
+ if species not in cfg_species:
399
  raise ValueError(
400
+ f"Species '{species}' is not available in this checkpoint. "
401
+ f"Available species: {cfg_species}"
 
402
  )
403
  return species, assembly
404
 
 
455
  input_ids = input_ids_cpu.to(device)
456
  # Species tokenization - match batch size
457
  batch_size = input_ids.shape[0]
458
+ species_ids = self.model.encode_species([species] * batch_size)
459
+ species_ids_tensor = species_ids.to(device)
 
 
460
 
461
  # Prediction interval (not used for slicing logits, just x-axis)
462
  pred_start = start + int(window_len * self.pred_center_offset_fraction)
463
  pred_end = pred_start + int(window_len * self.pred_center_fraction)
464
 
465
  # ✅ The source of truth for track IDs/names (your note)
466
+ bigwig_track_names = list(self.config.bigwigs_per_species[species])
467
 
468
  return {
469
  "input_ids": input_ids,
 
539
  out = self.model(
540
  input_ids=model_inputs["input_ids"],
541
  species_ids=model_inputs["species_ids"],
 
542
  )
543
  out["meta"] = meta
544
  return out
 
563
  if out.bigwig_track_names is None:
564
  raise ValueError(
565
  "bigwig_track_names missing; expected "
566
+ "cfg.bigwigs_per_species[species]."
567
  )
568
  if out.bed_element_names is None:
569
  raise ValueError("bed element names missing from config.")