davanstrien HF Staff commited on
Commit
c3f3746
·
verified ·
1 Parent(s): f0584d3

Sync from GitHub via hub-sync

Browse files
lighton-ocr2-saturate.py CHANGED
@@ -1,7 +1,7 @@
1
  # /// script
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
- # "saturate[hf]>=0.1.1",
5
  # "pillow>=10",
6
  # ]
7
  #
@@ -135,6 +135,7 @@ def main():
135
  help="Re-admit rows whose only record is an error row")
136
  args = ap.parse_args()
137
 
 
138
  from saturate import Auto, Engine, dataset_rows, pump
139
 
140
  target_size = 0 if args.no_resize else args.target_size
@@ -155,6 +156,13 @@ def main():
155
  "max_tokens": args.max_tokens,
156
  }
157
 
 
 
 
 
 
 
 
158
  def parse(row, body):
159
  usage = body.get("usage") or {}
160
  return {
@@ -169,7 +177,7 @@ def main():
169
  with Engine(SERVING["model"], engine="vllm", extra_args=extra) as endpoint:
170
  stats = pump(rows, to_request, parse, endpoint, output,
171
  window=Auto(initial=8, max_limit=48),
172
- retry_errors=args.retry_errors)
173
 
174
  print(f"https://huggingface.co/datasets/{args.output_dataset} "
175
  f"({stats.rows_processed} ok, {stats.rows_failed} error rows)", file=sys.stderr)
 
1
  # /// script
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
+ # "saturate[hf]==0.3.0",
5
  # "pillow>=10",
6
  # ]
7
  #
 
135
  help="Re-admit rows whose only record is an error row")
136
  args = ap.parse_args()
137
 
138
+ import pyarrow as pa
139
  from saturate import Auto, Engine, dataset_rows, pump
140
 
141
  target_size = 0 if args.no_resize else args.target_size
 
156
  "max_tokens": args.max_tokens,
157
  }
158
 
159
+ # Declared, so a part holding only error rows has the same columns as the rest
160
+ # (datasets.load_dataset reads every part with one schema).
161
+ schema = pa.schema([
162
+ ("id", pa.string()), ("error", pa.string()), ("markdown", pa.string()),
163
+ ("model", pa.string()), ("prompt_tokens", pa.int64()), ("completion_tokens", pa.int64()),
164
+ ]) # fmt: skip
165
+
166
  def parse(row, body):
167
  usage = body.get("usage") or {}
168
  return {
 
177
  with Engine(SERVING["model"], engine="vllm", extra_args=extra) as endpoint:
178
  stats = pump(rows, to_request, parse, endpoint, output,
179
  window=Auto(initial=8, max_limit=48),
180
+ retry_errors=args.retry_errors, schema=schema)
181
 
182
  print(f"https://huggingface.co/datasets/{args.output_dataset} "
183
  f"({stats.rows_processed} ok, {stats.rows_failed} error rows)", file=sys.stderr)
ovis-ocr2-saturate.py CHANGED
@@ -1,7 +1,7 @@
1
  # /// script
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
- # "saturate[hf]>=0.1.1",
5
  # "pillow>=10",
6
  # ]
7
  #
@@ -196,6 +196,7 @@ def main():
196
  help="Re-admit rows whose only record is an error row")
197
  args = ap.parse_args()
198
 
 
199
  from saturate import Auto, Engine, dataset_rows, pump
200
 
201
  rows = dataset_rows(
@@ -216,6 +217,13 @@ def main():
216
  "chat_template_kwargs": {"enable_thinking": False},
217
  }
218
 
 
 
 
 
 
 
 
219
  def parse(row, body):
220
  text = body["choices"][0]["message"]["content"].strip()
221
  if not args.keep_image_tags:
@@ -234,7 +242,7 @@ def main():
234
  with Engine(SERVING["model"], engine="vllm", extra_args=extra) as endpoint:
235
  stats = pump(rows, to_request, parse, endpoint, output,
236
  window=Auto(initial=8, max_limit=48),
237
- retry_errors=args.retry_errors)
238
 
239
  print(f"https://huggingface.co/datasets/{args.output_dataset} "
240
  f"({stats.rows_processed} ok, {stats.rows_failed} error rows)", file=sys.stderr)
 
1
  # /// script
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
+ # "saturate[hf]==0.3.0",
5
  # "pillow>=10",
6
  # ]
7
  #
 
196
  help="Re-admit rows whose only record is an error row")
197
  args = ap.parse_args()
198
 
199
+ import pyarrow as pa
200
  from saturate import Auto, Engine, dataset_rows, pump
201
 
202
  rows = dataset_rows(
 
217
  "chat_template_kwargs": {"enable_thinking": False},
218
  }
219
 
220
+ # Declared, so a part holding only error rows has the same columns as the rest
221
+ # (datasets.load_dataset reads every part with one schema).
222
+ schema = pa.schema([
223
+ ("id", pa.string()), ("error", pa.string()), ("markdown", pa.string()),
224
+ ("model", pa.string()), ("prompt_tokens", pa.int64()), ("completion_tokens", pa.int64()),
225
+ ]) # fmt: skip
226
+
227
  def parse(row, body):
228
  text = body["choices"][0]["message"]["content"].strip()
229
  if not args.keep_image_tags:
 
242
  with Engine(SERVING["model"], engine="vllm", extra_args=extra) as endpoint:
243
  stats = pump(rows, to_request, parse, endpoint, output,
244
  window=Auto(initial=8, max_limit=48),
245
+ retry_errors=args.retry_errors, schema=schema)
246
 
247
  print(f"https://huggingface.co/datasets/{args.output_dataset} "
248
  f"({stats.rows_processed} ok, {stats.rows_failed} error rows)", file=sys.stderr)
unlimited-ocr2-live.py CHANGED
@@ -1,7 +1,7 @@
1
  # /// script
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
- # "saturate[hf]==0.2.0",
5
  # "pillow>=10",
6
  # ]
7
  #
@@ -691,7 +691,6 @@ def main():
691
  args = ap.parse_args()
692
 
693
  import fsspec
694
- import saturate.transport
695
  from saturate import Auto, Engine, pump
696
 
697
  rows = list(list_windows(args.input, args.pages_per_request, args.max_pages))
@@ -736,9 +735,8 @@ def main():
736
  is_repo_id = re.fullmatch(r"[\w-][\w.-]*/[\w.-]*[\w-]", args.output) and not os.path.exists(args.output)
737
  output = f"hf://datasets/{args.output}/data" if is_repo_id else args.output
738
 
739
- # One request is minutes of decoding. saturate 0.2.0 caps a request's retries at
740
- # 300 s in total, which a retried 16-page request never fits in; match the read timeout.
741
- saturate.transport.RETRY_BUDGET_S = 3600.0
742
  if live is not None:
743
  live.phase("Installing Baidu's SGLang build")
744
  cmd = start_server_cmd()
 
1
  # /// script
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
+ # "saturate[hf]==0.3.0",
5
  # "pillow>=10",
6
  # ]
7
  #
 
691
  args = ap.parse_args()
692
 
693
  import fsspec
 
694
  from saturate import Auto, Engine, pump
695
 
696
  rows = list(list_windows(args.input, args.pages_per_request, args.max_pages))
 
735
  is_repo_id = re.fullmatch(r"[\w-][\w.-]*/[\w.-]*[\w-]", args.output) and not os.path.exists(args.output)
736
  output = f"hf://datasets/{args.output}/data" if is_repo_id else args.output
737
 
738
+ # One request is minutes of decoding: read_timeout=3600 below, and a row's retries get
739
+ # 2 x read_timeout in total (saturate's default retry budget).
 
740
  if live is not None:
741
  live.phase("Installing Baidu's SGLang build")
742
  cmd = start_server_cmd()
unlimited-ocr2-saturate.py CHANGED
@@ -1,7 +1,7 @@
1
  # /// script
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
- # "saturate[hf]==0.2.0",
5
  # "pillow>=10",
6
  # "pymupdf>=1.24",
7
  # ]
@@ -527,14 +527,8 @@ def main():
527
  # headroom (a100-large: 8 x 32-page windows used ~25% of KV) and flush often,
528
  # since each row is expensive to redo.
529
  window = Auto(initial=32, max_limit=64)
530
- # saturate caps a row's retries at RETRY_BUDGET_S (300 s, counted from the first
531
- # attempt), which is shorter than one legitimate multi-page generation here, so a
532
- # transient first-attempt failure always ended in a TimeoutError row. Match the
533
- # read timeout until saturate exposes this as a pump() argument.
534
- import saturate.transport
535
-
536
- saturate.transport.RETRY_BUDGET_S = 3600.0
537
-
538
  def run_passes(endpoint, headers=None):
539
  common = {"retry_errors": args.retry_errors, "headers": headers,
540
  "prepare_workers": args.prepare_workers, "read_timeout": 3600}
 
1
  # /// script
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
+ # "saturate[hf]==0.3.0",
5
  # "pillow>=10",
6
  # "pymupdf>=1.24",
7
  # ]
 
527
  # headroom (a100-large: 8 x 32-page windows used ~25% of KV) and flush often,
528
  # since each row is expensive to redo.
529
  window = Auto(initial=32, max_limit=64)
530
+ # read_timeout=3600: one window is minutes of decode. A row's retries then get
531
+ # 2 x read_timeout in total (saturate's default retry budget).
 
 
 
 
 
 
532
  def run_passes(endpoint, headers=None):
533
  common = {"retry_errors": args.retry_errors, "headers": headers,
534
  "prepare_workers": args.prepare_workers, "read_timeout": 3600}
unlimited-ocr2.py CHANGED
@@ -1,7 +1,7 @@
1
  # /// script
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
- # "saturate[hf]==0.2.0",
5
  # "pillow>=10",
6
  # ]
7
  #
@@ -279,7 +279,6 @@ def main():
279
  SERVING["env"]["SGLANG_UOCR_MAX_PAGE_TOKENS"] = str(args.max_page_tokens)
280
 
281
  import fsspec
282
- import saturate.transport
283
  from saturate import Auto, Engine, pump
284
 
285
  rows = list(list_windows(args.input, args.pages_per_request, args.max_pages))
@@ -335,9 +334,8 @@ def main():
335
  is_repo_id = re.fullmatch(r"[\w-][\w.-]*/[\w.-]*[\w-]", args.output) and not os.path.exists(args.output)
336
  output = f"hf://datasets/{args.output}/data" if is_repo_id else args.output
337
 
338
- # One request is minutes of decoding. saturate 0.2.0 caps a request's retries at
339
- # 300 s in total, which a retried 16-page request never fits in; match the read timeout.
340
- saturate.transport.RETRY_BUDGET_S = 3600.0
341
  with Engine(SERVING["model"], engine="sglang", cmd=start_server_cmd()) as endpoint:
342
  stats = pump(rows, to_request, parse, endpoint, output,
343
  window=Auto(initial=32, max_limit=64), # long requests: start wide
 
1
  # /// script
2
  # requires-python = ">=3.11"
3
  # dependencies = [
4
+ # "saturate[hf]==0.3.0",
5
  # "pillow>=10",
6
  # ]
7
  #
 
279
  SERVING["env"]["SGLANG_UOCR_MAX_PAGE_TOKENS"] = str(args.max_page_tokens)
280
 
281
  import fsspec
 
282
  from saturate import Auto, Engine, pump
283
 
284
  rows = list(list_windows(args.input, args.pages_per_request, args.max_pages))
 
334
  is_repo_id = re.fullmatch(r"[\w-][\w.-]*/[\w.-]*[\w-]", args.output) and not os.path.exists(args.output)
335
  output = f"hf://datasets/{args.output}/data" if is_repo_id else args.output
336
 
337
+ # One request is minutes of decoding: read_timeout=3600 below, and a row's retries get
338
+ # 2 x read_timeout in total (saturate's default retry budget).
 
339
  with Engine(SERVING["model"], engine="sglang", cmd=start_server_cmd()) as endpoint:
340
  stats = pump(rows, to_request, parse, endpoint, output,
341
  window=Auto(initial=32, max_limit=64), # long requests: start wide