Remove _patch_convert_script method as it's not necessary anymore
Browse files
app.py
CHANGED
|
@@ -86,7 +86,6 @@ class ModelConverter:
|
|
| 86 |
try:
|
| 87 |
urlretrieve(archive_url, archive_path)
|
| 88 |
self._extract_archive(archive_path)
|
| 89 |
-
# self._patch_convert_script()
|
| 90 |
self._install_scripts_requirements()
|
| 91 |
logger.info("Repository downloaded and extracted successfully")
|
| 92 |
except Exception as e:
|
|
@@ -119,44 +118,6 @@ class ModelConverter:
|
|
| 119 |
check=True,
|
| 120 |
)
|
| 121 |
|
| 122 |
-
def _patch_convert_script(self) -> None:
|
| 123 |
-
"""Patch transformers.js convert script to force eager attention for better ONNX compatibility."""
|
| 124 |
-
path = self.config.repo_path / "scripts" / "convert.py"
|
| 125 |
-
if not path.exists():
|
| 126 |
-
return
|
| 127 |
-
try:
|
| 128 |
-
text = path.read_text(encoding="utf-8")
|
| 129 |
-
marker = "export_kwargs = dict("
|
| 130 |
-
if marker in text:
|
| 131 |
-
lines = text.splitlines()
|
| 132 |
-
start_idx = None
|
| 133 |
-
paren = 0
|
| 134 |
-
for i, line in enumerate(lines):
|
| 135 |
-
if marker in line:
|
| 136 |
-
start_idx = i
|
| 137 |
-
break
|
| 138 |
-
if start_idx is not None:
|
| 139 |
-
for k in range(start_idx, len(lines)):
|
| 140 |
-
paren += lines[k].count("(")
|
| 141 |
-
paren -= lines[k].count(")")
|
| 142 |
-
if paren <= 0:
|
| 143 |
-
insert_at = k + 1
|
| 144 |
-
lines.insert(
|
| 145 |
-
insert_at,
|
| 146 |
-
" export_kwargs.setdefault('model_kwargs', {})",
|
| 147 |
-
)
|
| 148 |
-
lines.insert(
|
| 149 |
-
insert_at + 1,
|
| 150 |
-
" export_kwargs['model_kwargs']['attn_implementation'] = 'eager'",
|
| 151 |
-
)
|
| 152 |
-
patched = "\n".join(lines) + (
|
| 153 |
-
"\n" if text.endswith("\n") else ""
|
| 154 |
-
)
|
| 155 |
-
path.write_text(patched, encoding="utf-8")
|
| 156 |
-
break
|
| 157 |
-
except Exception:
|
| 158 |
-
pass
|
| 159 |
-
|
| 160 |
def _run_conversion_subprocess(
|
| 161 |
self, input_model_id: str, extra_args: List[str] = None
|
| 162 |
) -> subprocess.CompletedProcess:
|
|
|
|
| 86 |
try:
|
| 87 |
urlretrieve(archive_url, archive_path)
|
| 88 |
self._extract_archive(archive_path)
|
|
|
|
| 89 |
self._install_scripts_requirements()
|
| 90 |
logger.info("Repository downloaded and extracted successfully")
|
| 91 |
except Exception as e:
|
|
|
|
| 118 |
check=True,
|
| 119 |
)
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
def _run_conversion_subprocess(
|
| 122 |
self, input_model_id: str, extra_args: List[str] = None
|
| 123 |
) -> subprocess.CompletedProcess:
|