Skip to content

[Taskflow] Fix the recognition bug of json format with both PIR suffix and id2label #10487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions paddlenlp/taskflow/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,28 @@
"""

def _get_static_model_name(self):
names = []
model_candidates = []

Check warning on line 131 in paddlenlp/taskflow/task.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/taskflow/task.py#L131

Added line #L131 was not covered by tests
for file_name in os.listdir(self._task_path):
if PADDLE_INFERENCE_MODEL_SUFFIX in file_name:
names.append(file_name[: -len(PADDLE_INFERENCE_MODEL_SUFFIX)])
if len(names) == 0:
raise IOError(f"{self._task_path} should include '{PADDLE_INFERENCE_MODEL_SUFFIX}' file.")
if len(names) > 1:
logger.warning(f"{self._task_path} includes more than one '{PADDLE_INFERENCE_MODEL_SUFFIX}' file.")
return names[0]
if file_name.endswith(PADDLE_INFERENCE_MODEL_SUFFIX):
prefix = file_name[: -len(PADDLE_INFERENCE_MODEL_SUFFIX)]
param_file = prefix + PADDLE_INFERENCE_WEIGHTS_SUFFIX
if os.path.exists(os.path.join(self._task_path, param_file)):
model_candidates.append(prefix)

Check warning on line 137 in paddlenlp/taskflow/task.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/taskflow/task.py#L133-L137

Added lines #L133 - L137 were not covered by tests

if not model_candidates:
raise IOError(

Check warning on line 140 in paddlenlp/taskflow/task.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/taskflow/task.py#L139-L140

Added lines #L139 - L140 were not covered by tests
f"{self._task_path} should include at least one valid model structure file "
f"({PADDLE_INFERENCE_MODEL_SUFFIX}) with corresponding {PADDLE_INFERENCE_WEIGHTS_SUFFIX}."
)

for preferred in ["inference", "model"]:
if preferred in model_candidates:
return preferred

Check warning on line 147 in paddlenlp/taskflow/task.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/taskflow/task.py#L145-L147

Added lines #L145 - L147 were not covered by tests

if len(model_candidates) > 1:
logger.warning(f"{self._task_path} includes multiple model pairs. Defaulting to: {model_candidates[0]}")

Check warning on line 150 in paddlenlp/taskflow/task.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/taskflow/task.py#L149-L150

Added lines #L149 - L150 were not covered by tests

return model_candidates[0]

Check warning on line 152 in paddlenlp/taskflow/task.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/taskflow/task.py#L152

Added line #L152 was not covered by tests

def _check_task_files(self):
"""
Expand Down