Commit
·
916ff8e
1
Parent(s):
ea32fa8
keep viewer
Browse files- olmocr2-vllm.py +22 -14
olmocr2-vllm.py
CHANGED
|
@@ -96,7 +96,7 @@ def parse_yaml_frontmatter(text: str) -> tuple[dict, str]:
|
|
| 96 |
(metadata_dict, content_without_frontmatter)
|
| 97 |
"""
|
| 98 |
# Match YAML front matter between --- markers
|
| 99 |
-
pattern = r
|
| 100 |
match = re.match(pattern, text.strip(), re.DOTALL)
|
| 101 |
|
| 102 |
if match:
|
|
@@ -179,7 +179,6 @@ def create_dataset_card(
|
|
| 179 |
model_name = model.split("/")[-1]
|
| 180 |
|
| 181 |
return f"""---
|
| 182 |
-
viewer: false
|
| 183 |
tags:
|
| 184 |
- ocr
|
| 185 |
- document-processing
|
|
@@ -315,6 +314,7 @@ def main(
|
|
| 315 |
seed: Random seed for shuffling
|
| 316 |
"""
|
| 317 |
import time
|
|
|
|
| 318 |
start_time = time.time()
|
| 319 |
|
| 320 |
# Check CUDA availability
|
|
@@ -396,7 +396,9 @@ def main(
|
|
| 396 |
|
| 397 |
# Log warning if generation didn't finish naturally
|
| 398 |
if finish_reason != "stop":
|
| 399 |
-
logger.warning(
|
|
|
|
|
|
|
| 400 |
|
| 401 |
metadata, content = parse_yaml_frontmatter(response_text)
|
| 402 |
all_outputs.append(content)
|
|
@@ -405,25 +407,31 @@ def main(
|
|
| 405 |
# Add results to dataset
|
| 406 |
# Check if columns already exist and handle appropriately
|
| 407 |
if output_column in ds.column_names:
|
| 408 |
-
logger.warning(
|
|
|
|
|
|
|
| 409 |
ds = ds.remove_columns([output_column])
|
| 410 |
ds = ds.add_column(output_column, all_outputs)
|
| 411 |
|
| 412 |
if metadata_column_name in ds.column_names:
|
| 413 |
-
logger.warning(
|
|
|
|
|
|
|
| 414 |
ds = ds.remove_columns([metadata_column_name])
|
| 415 |
ds = ds.add_column(metadata_column_name, all_metadata)
|
| 416 |
|
| 417 |
# Add inference information
|
| 418 |
-
inference_info = json.dumps(
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
|
|
|
|
|
|
| 427 |
|
| 428 |
# Handle existing inference_info column
|
| 429 |
if inference_info_column in ds.column_names:
|
|
|
|
| 96 |
(metadata_dict, content_without_frontmatter)
|
| 97 |
"""
|
| 98 |
# Match YAML front matter between --- markers
|
| 99 |
+
pattern = r"^---\s*\n(.*?)\n---\s*\n(.*)$"
|
| 100 |
match = re.match(pattern, text.strip(), re.DOTALL)
|
| 101 |
|
| 102 |
if match:
|
|
|
|
| 179 |
model_name = model.split("/")[-1]
|
| 180 |
|
| 181 |
return f"""---
|
|
|
|
| 182 |
tags:
|
| 183 |
- ocr
|
| 184 |
- document-processing
|
|
|
|
| 314 |
seed: Random seed for shuffling
|
| 315 |
"""
|
| 316 |
import time
|
| 317 |
+
|
| 318 |
start_time = time.time()
|
| 319 |
|
| 320 |
# Check CUDA availability
|
|
|
|
| 396 |
|
| 397 |
# Log warning if generation didn't finish naturally
|
| 398 |
if finish_reason != "stop":
|
| 399 |
+
logger.warning(
|
| 400 |
+
f"Generation did not finish naturally (reason: {finish_reason}), output may be incomplete"
|
| 401 |
+
)
|
| 402 |
|
| 403 |
metadata, content = parse_yaml_frontmatter(response_text)
|
| 404 |
all_outputs.append(content)
|
|
|
|
| 407 |
# Add results to dataset
|
| 408 |
# Check if columns already exist and handle appropriately
|
| 409 |
if output_column in ds.column_names:
|
| 410 |
+
logger.warning(
|
| 411 |
+
f"Column '{output_column}' already exists, it will be overwritten"
|
| 412 |
+
)
|
| 413 |
ds = ds.remove_columns([output_column])
|
| 414 |
ds = ds.add_column(output_column, all_outputs)
|
| 415 |
|
| 416 |
if metadata_column_name in ds.column_names:
|
| 417 |
+
logger.warning(
|
| 418 |
+
f"Column '{metadata_column_name}' already exists, it will be overwritten"
|
| 419 |
+
)
|
| 420 |
ds = ds.remove_columns([metadata_column_name])
|
| 421 |
ds = ds.add_column(metadata_column_name, all_metadata)
|
| 422 |
|
| 423 |
# Add inference information
|
| 424 |
+
inference_info = json.dumps(
|
| 425 |
+
{
|
| 426 |
+
"model": model,
|
| 427 |
+
"script": "olmocr2-vllm.py",
|
| 428 |
+
"version": "1.0.0",
|
| 429 |
+
"timestamp": datetime.now().isoformat(),
|
| 430 |
+
"batch_size": batch_size,
|
| 431 |
+
"max_tokens": max_tokens,
|
| 432 |
+
"temperature": temperature,
|
| 433 |
+
}
|
| 434 |
+
)
|
| 435 |
|
| 436 |
# Handle existing inference_info column
|
| 437 |
if inference_info_column in ds.column_names:
|