euIaxs22 commited on
Commit
10fdfb8
·
verified ·
1 Parent(s): dff87bb

Update services/vince_server.py

Browse files
Files changed (1) hide show
  1. services/vince_server.py +19 -13
services/vince_server.py CHANGED
@@ -7,12 +7,12 @@ from typing import List, Optional
7
  from omegaconf import OmegaConf, open_dict
8
 
9
  # Copiado/adaptado do vincie.py: uso de HF Hub
10
- from huggingface_hub import hf_hub_download, list_repo_files, HfApi # [attached_file:2]
11
 
12
  VINCIE_DIR = Path(os.getenv("VINCIE_DIR", "/app/VINCIE"))
13
- VINCE_GIT_URL = os.getenv("VINCE_GIT_URL", "https://github.com/ByteDance-Seed/VINCIE") # [attached_file:2]
14
- VINCE_REPO_ID = os.getenv("VINCE_REPO_ID", "ByteDance-Seed/VINCIE-3B") # [attached_file:2]
15
- VINCE_CKPT = Path(os.getenv("VINCE_CKPT", "/app/ckpt/VINCIE-3B")) # [attached_file:2]
16
 
17
  if str(VINCIE_DIR) not in sys.path:
18
  sys.path.insert(0, str(VINCIE_DIR))
@@ -33,9 +33,10 @@ class VinceServer:
33
  self.config_path = config_path
34
  self.output_root = Path(output_root); self.output_root.mkdir(parents=True, exist_ok=True)
35
  overrides = list(base_overrides or [])
 
36
  self.HF_HOME = Path(os.getenv("HF_HOME", "/data/.cache/huggingface"))
37
  self.HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN") or None
38
-
39
  # 1) Clonar/garantir repo
40
  self.ensure_repo()
41
 
@@ -63,7 +64,7 @@ class VinceServer:
63
  # ==== Helpers de bootstrap copiados/adaptados do vincie.py ====
64
 
65
  def ensure_repo(self) -> None:
66
- """Clona o repositório oficial quando ausente (idempotente).""" # [attached_file:2]
67
  if not VINCIE_DIR.exists():
68
  subprocess.run(["git", "clone", VINCE_GIT_URL, str(VINCIE_DIR)], check=True)
69
 
@@ -71,7 +72,7 @@ class VinceServer:
71
  """
72
  Baixa TODOS os arquivos do modelo do Hub (VINCE_REPO_ID) para VINCE_CKPT,
73
  preservando subdiretórios. Critério de pular download: arquivo > 1MB.
74
- Cria pastas necessárias. # [attached_file:2]
75
  """
76
  VINCE_CKPT.mkdir(parents=True, exist_ok=True)
77
  token = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
@@ -106,12 +107,13 @@ class VinceServer:
106
  hf_hub_download(
107
  repo_id=VINCE_REPO_ID,
108
  filename=rel_path,
109
- local_dir=str(VINCE_CKPT),
110
  cache_dir=str(self.HF_HOME),
 
111
  #local_dir_use_symlinks=False,
112
  token=token,
113
  #force_download=False,
114
  #local_files_only=False,
 
115
  )
116
  downloaded += 1
117
  except Exception as de:
@@ -122,7 +124,7 @@ class VinceServer:
122
  """
123
  Cria symlink compatível para caminhos relativos do repo:
124
  /app/VINCIE/ckpt/VINCIE-3B -> /app/ckpt/VINCIE-3B.
125
- Não remove diretórios reais; apenas substitui symlink divergente. # [attached_file:2]
126
  """
127
  repo_ckpt_dir = VINCIE_DIR / "ckpt"
128
  repo_ckpt_dir.mkdir(parents=True, exist_ok=True)
@@ -166,8 +168,6 @@ class VinceServer:
166
  raise RuntimeError(f"[vince_server] missing bootstrap step: {name}")
167
  fn()
168
 
169
-
170
-
171
  def _apply_generation_overrides(self, cfg, *, output_dir: Path,
172
  image_path: Optional[str]=None,
173
  prompts: Optional[List[str]]=None,
@@ -213,7 +213,13 @@ class VinceServer:
213
  fn = getattr(self.gen, name, None)
214
  if callable(fn):
215
  print(f"[vince_server] using inference method: {name}")
216
- return fn(self.config)
 
 
 
 
 
 
217
  raise RuntimeError("[vince_server] no valid inference method found")
218
 
219
  def _cleanup(self):
@@ -266,4 +272,4 @@ class VinceServer:
266
  self.config = cfg
267
  result = self._infer_once()
268
  self._cleanup()
269
- return out_dir
 
7
  from omegaconf import OmegaConf, open_dict
8
 
9
  # Copiado/adaptado do vincie.py: uso de HF Hub
10
+ from huggingface_hub import hf_hub_download, list_repo_files, HfApi
11
 
12
  VINCIE_DIR = Path(os.getenv("VINCIE_DIR", "/app/VINCIE"))
13
+ VINCE_GIT_URL = os.getenv("VINCE_GIT_URL", "https://github.com/ByteDance-Seed/VINCIE")
14
+ VINCE_REPO_ID = os.getenv("VINCE_REPO_ID", "ByteDance-Seed/VINCIE-3B")
15
+ VINCE_CKPT = Path(os.getenv("VINCE_CKPT", "/app/ckpt/VINCIE-3B"))
16
 
17
  if str(VINCIE_DIR) not in sys.path:
18
  sys.path.insert(0, str(VINCIE_DIR))
 
33
  self.config_path = config_path
34
  self.output_root = Path(output_root); self.output_root.mkdir(parents=True, exist_ok=True)
35
  overrides = list(base_overrides or [])
36
+
37
  self.HF_HOME = Path(os.getenv("HF_HOME", "/data/.cache/huggingface"))
38
  self.HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN") or None
39
+
40
  # 1) Clonar/garantir repo
41
  self.ensure_repo()
42
 
 
64
  # ==== Helpers de bootstrap copiados/adaptados do vincie.py ====
65
 
66
  def ensure_repo(self) -> None:
67
+ """Clona o repositório oficial quando ausente (idempotente)."""
68
  if not VINCIE_DIR.exists():
69
  subprocess.run(["git", "clone", VINCE_GIT_URL, str(VINCIE_DIR)], check=True)
70
 
 
72
  """
73
  Baixa TODOS os arquivos do modelo do Hub (VINCE_REPO_ID) para VINCE_CKPT,
74
  preservando subdiretórios. Critério de pular download: arquivo > 1MB.
75
+ Cria pastas necessárias.
76
  """
77
  VINCE_CKPT.mkdir(parents=True, exist_ok=True)
78
  token = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
 
107
  hf_hub_download(
108
  repo_id=VINCE_REPO_ID,
109
  filename=rel_path,
 
110
  cache_dir=str(self.HF_HOME),
111
+ local_dir=str(VINCE_CKPT),
112
  #local_dir_use_symlinks=False,
113
  token=token,
114
  #force_download=False,
115
  #local_files_only=False,
116
+ #revision=repo_revision,
117
  )
118
  downloaded += 1
119
  except Exception as de:
 
124
  """
125
  Cria symlink compatível para caminhos relativos do repo:
126
  /app/VINCIE/ckpt/VINCIE-3B -> /app/ckpt/VINCIE-3B.
127
+ Não remove diretórios reais; apenas substitui symlink divergente.
128
  """
129
  repo_ckpt_dir = VINCIE_DIR / "ckpt"
130
  repo_ckpt_dir.mkdir(parents=True, exist_ok=True)
 
168
  raise RuntimeError(f"[vince_server] missing bootstrap step: {name}")
169
  fn()
170
 
 
 
171
  def _apply_generation_overrides(self, cfg, *, output_dir: Path,
172
  image_path: Optional[str]=None,
173
  prompts: Optional[List[str]]=None,
 
213
  fn = getattr(self.gen, name, None)
214
  if callable(fn):
215
  print(f"[vince_server] using inference method: {name}")
216
+ # =============================================================
217
+ # CORREÇÃO APLICADA AQUI
218
+ # O método de inferência (ex: inference_loop) não espera
219
+ # argumentos, pois acessa a configuração através do `self`
220
+ # do seu próprio objeto (`self.gen`).
221
+ return fn()
222
+ # =============================================================
223
  raise RuntimeError("[vince_server] no valid inference method found")
224
 
225
  def _cleanup(self):
 
272
  self.config = cfg
273
  result = self._infer_once()
274
  self._cleanup()
275
+ return out_dir