carlex3321 commited on
Commit
7ce5a63
·
verified ·
1 Parent(s): 683a566

Update services/vincie.py

Browse files
Files changed (1) hide show
  1. services/vincie.py +17 -15
services/vincie.py CHANGED
@@ -63,31 +63,33 @@ class VincieService:
63
  # Clona com --depth 1 para baixar apenas a versão mais recente
64
  subprocess.run(["git", "clone", "--depth", "1", git_url, str(self.repo_dir)], check=True)
65
 
 
 
66
  def ensure_model(self, hf_token: Optional[str] = None) -> None:
67
- """Baixa os arquivos de checkpoint e cria o link simbólico necessário."""
68
  self.ckpt_dir.mkdir(parents=True, exist_ok=True)
69
  token = hf_token or os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
70
-
71
- def _need_download(p: Path) -> bool:
72
- try: return not (p.exists() and p.stat().st_size > 1_000_000)
73
- except FileNotFoundError: return True
74
-
75
- for fname in ["dit.pth", "vae.pth"]:
76
- dst = self.ckpt_dir / fname
77
- if _need_download(dst):
78
- print(f"Baixando {fname} de {self.repo_id}...")
79
- hf_hub_download(repo_id=self.repo_id, filename=fname, local_dir=str(self.ckpt_dir), token=token)
80
-
 
81
  link_path = self.repo_dir / "ckpt" / "VINCIE-3B"
82
  if not link_path.exists():
83
  try:
84
- if link_path.is_symlink(): link_path.unlink()
 
85
  link_path.symlink_to(self.ckpt_dir, target_is_directory=True)
86
  except Exception as e:
87
  print(f"Aviso: falha ao criar o link simbólico do checkpoint: {e}")
88
 
89
- # ---------- Executor Principal com Suporte a Multi-GPU ----------
90
-
91
  def _run_vincie(self, overrides: List[str], work_output: Path, video_mode: bool = False, num_gpus: int = 1) -> None:
92
  """
93
  Invoca o main.py do VINCIE, usando torchrun para execução distribuída se num_gpus > 1.
 
63
  # Clona com --depth 1 para baixar apenas a versão mais recente
64
  subprocess.run(["git", "clone", "--depth", "1", git_url, str(self.repo_dir)], check=True)
65
 
66
+ from huggingface_hub import snapshot_download
67
+
68
  def ensure_model(self, hf_token: Optional[str] = None) -> None:
69
+ """Baixa o checkpoint completo e cria o link simbólico necessário."""
70
  self.ckpt_dir.mkdir(parents=True, exist_ok=True)
71
  token = hf_token or os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
72
+
73
+ # Baixa o snapshot completo do repositório
74
+ print(f"Baixando snapshot completo de {self.repo_id} para {self.ckpt_dir}...")
75
+ snapshot_download(
76
+ repo_id=self.repo_id,
77
+ local_dir=str(self.ckpt_dir),
78
+ token=token,
79
+ resume_download=True,
80
+ local_dir_use_symlinks=False
81
+ )
82
+
83
+ # Cria symlink se necessário
84
  link_path = self.repo_dir / "ckpt" / "VINCIE-3B"
85
  if not link_path.exists():
86
  try:
87
+ if link_path.is_symlink():
88
+ link_path.unlink()
89
  link_path.symlink_to(self.ckpt_dir, target_is_directory=True)
90
  except Exception as e:
91
  print(f"Aviso: falha ao criar o link simbólico do checkpoint: {e}")
92
 
 
 
93
  def _run_vincie(self, overrides: List[str], work_output: Path, video_mode: bool = False, num_gpus: int = 1) -> None:
94
  """
95
  Invoca o main.py do VINCIE, usando torchrun para execução distribuída se num_gpus > 1.