Florent Gbelidji commited on
Commit
d46c985
·
verified ·
1 Parent(s): bdddedb

Sync DeepSeek OCR HF job code

Browse files
Files changed (2) hide show
  1. ds_batch_ocr/config.py +4 -0
  2. ds_batch_ocr/hf_io.py +20 -8
ds_batch_ocr/config.py CHANGED
@@ -105,6 +105,7 @@ class InferenceSettings:
105
  class ArtifactLocator:
106
  strategy: str = "local"
107
  repo_id: Optional[str] = None
 
108
  job_id: Optional[str] = None
109
  job_owner: Optional[str] = None
110
  uri: Optional[str] = None
@@ -117,6 +118,7 @@ class ArtifactLocator:
117
  env = os.environ
118
 
119
  repo_id = (env.get(f"{stage}_JOB_REPO") or "").strip() or (env.get(f"{stage}_REPO_ID") or "").strip() or None
 
120
  job_id = (env.get(f"{stage}_JOB_ID") or "").strip() or None
121
  job_owner = (env.get(f"{stage}_JOB_OWNER") or "").strip() or None
122
  uri = (env.get(f"{stage}_ARTIFACT_URI") or "").strip() or None
@@ -142,6 +144,7 @@ class ArtifactLocator:
142
  locator = cls(
143
  strategy=strategy,
144
  repo_id=repo_id,
 
145
  job_id=job_id,
146
  job_owner=job_owner,
147
  uri=uri,
@@ -154,6 +157,7 @@ class ArtifactLocator:
154
  {
155
  "strategy": locator.strategy,
156
  "repo_id": locator.repo_id,
 
157
  "job_id": locator.job_id,
158
  "job_owner": locator.job_owner,
159
  "uri": locator.uri,
 
105
  class ArtifactLocator:
106
  strategy: str = "local"
107
  repo_id: Optional[str] = None
108
+ repo_type: Optional[str] = None
109
  job_id: Optional[str] = None
110
  job_owner: Optional[str] = None
111
  uri: Optional[str] = None
 
118
  env = os.environ
119
 
120
  repo_id = (env.get(f"{stage}_JOB_REPO") or "").strip() or (env.get(f"{stage}_REPO_ID") or "").strip() or None
121
+ repo_type = (env.get(f"{stage}_REPO_TYPE") or "").strip() or None
122
  job_id = (env.get(f"{stage}_JOB_ID") or "").strip() or None
123
  job_owner = (env.get(f"{stage}_JOB_OWNER") or "").strip() or None
124
  uri = (env.get(f"{stage}_ARTIFACT_URI") or "").strip() or None
 
144
  locator = cls(
145
  strategy=strategy,
146
  repo_id=repo_id,
147
+ repo_type=repo_type,
148
  job_id=job_id,
149
  job_owner=job_owner,
150
  uri=uri,
 
157
  {
158
  "strategy": locator.strategy,
159
  "repo_id": locator.repo_id,
160
+ "repo_type": locator.repo_type,
161
  "job_id": locator.job_id,
162
  "job_owner": locator.job_owner,
163
  "uri": locator.uri,
ds_batch_ocr/hf_io.py CHANGED
@@ -25,28 +25,36 @@ def unpack_archives(target_dir: Path) -> None:
25
  archive.unlink()
26
 
27
 
28
- def download_job_artifact(repo_id: str, target_dir: Path) -> None:
29
  LOGGER.info("Downloading job artifact %s -> %s", repo_id, target_dir)
30
  actual_repo_id = repo_id
31
- repo_type = None
32
 
33
  if repo_id.startswith("jobs/"):
34
  parts = repo_id.split("/", 2)
35
  if len(parts) == 3:
36
- repo_type = "job"
37
  actual_repo_id = f"{parts[1]}/{parts[2]}"
38
  else:
39
  LOGGER.warning("Unexpected jobs repo format: %s", repo_id)
40
  elif repo_id.startswith("datasets/"):
41
- repo_type = "dataset"
42
  actual_repo_id = repo_id.split("/", 1)[1]
43
  elif repo_id.startswith("models/"):
44
- repo_type = "model"
45
  actual_repo_id = repo_id.split("/", 1)[1]
46
 
 
 
 
 
 
 
 
 
47
  snapshot_download(
48
  repo_id=actual_repo_id,
49
- repo_type=repo_type,
50
  local_dir=target_dir,
51
  local_dir_use_symlinks=False,
52
  ignore_patterns=("logs/**",),
@@ -91,10 +99,14 @@ def resolve_stage_dir(base_dir: Path, locator: ArtifactLocator) -> Path:
91
  def _handle_hf_hub(locator: ArtifactLocator, base_dir: Path) -> None:
92
  repo_id = locator.repo_id or locator.uri
93
  if repo_id:
94
- download_job_artifact(repo_id, base_dir)
95
  return
96
  if locator.job_id and locator.job_owner:
97
- download_job_artifact(f"jobs/{locator.job_owner}/{locator.job_id}", base_dir)
 
 
 
 
98
  return
99
  LOGGER.debug("HF locator missing repo/job information; treating as local artifacts.")
100
 
 
25
  archive.unlink()
26
 
27
 
28
+ def download_job_artifact(repo_id: str, target_dir: Path, repo_type: Optional[str] = None) -> None:
29
  LOGGER.info("Downloading job artifact %s -> %s", repo_id, target_dir)
30
  actual_repo_id = repo_id
31
+ normalized_repo_type = (repo_type or "").strip() or None
32
 
33
  if repo_id.startswith("jobs/"):
34
  parts = repo_id.split("/", 2)
35
  if len(parts) == 3:
36
+ normalized_repo_type = normalized_repo_type or "job"
37
  actual_repo_id = f"{parts[1]}/{parts[2]}"
38
  else:
39
  LOGGER.warning("Unexpected jobs repo format: %s", repo_id)
40
  elif repo_id.startswith("datasets/"):
41
+ normalized_repo_type = normalized_repo_type or "dataset"
42
  actual_repo_id = repo_id.split("/", 1)[1]
43
  elif repo_id.startswith("models/"):
44
+ normalized_repo_type = normalized_repo_type or "model"
45
  actual_repo_id = repo_id.split("/", 1)[1]
46
 
47
+ if normalized_repo_type:
48
+ normalized_repo_type = normalized_repo_type.lower()
49
+ if normalized_repo_type not in {"dataset", "model", "space", "job"}:
50
+ LOGGER.warning("Unknown repo_type '%s'; defaulting to dataset", normalized_repo_type)
51
+ normalized_repo_type = "dataset"
52
+ else:
53
+ normalized_repo_type = "dataset"
54
+
55
  snapshot_download(
56
  repo_id=actual_repo_id,
57
+ repo_type=normalized_repo_type,
58
  local_dir=target_dir,
59
  local_dir_use_symlinks=False,
60
  ignore_patterns=("logs/**",),
 
99
  def _handle_hf_hub(locator: ArtifactLocator, base_dir: Path) -> None:
100
  repo_id = locator.repo_id or locator.uri
101
  if repo_id:
102
+ download_job_artifact(repo_id, base_dir, repo_type=locator.repo_type)
103
  return
104
  if locator.job_id and locator.job_owner:
105
+ download_job_artifact(
106
+ f"jobs/{locator.job_owner}/{locator.job_id}",
107
+ base_dir,
108
+ repo_type=locator.repo_type or "job",
109
+ )
110
  return
111
  LOGGER.debug("HF locator missing repo/job information; treating as local artifacts.")
112