urroxyz commited on
Commit
cc245ef
·
verified ·
1 Parent(s): d10f691

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -13,7 +13,7 @@ from huggingface_hub import HfApi, whoami
13
  from torch.jit import TracerWarning
14
  from transformers import AutoConfig, GenerationConfig
15
 
16
- # Suppress TorchScript tracer warnings globally
17
  warnings.filterwarnings("ignore", category=TracerWarning)
18
 
19
  logging.basicConfig(level=logging.INFO)
@@ -100,15 +100,15 @@ class ModelConverter:
100
  def convert_model(self, input_model_id: str) -> Tuple[bool, Optional[str]]:
101
  """
102
  Convert the model to ONNX format, always exporting attention maps.
103
- Relocate generation parameters and suppress tracer warnings.
104
- Strip out the static relocation warning from stderr.
105
  """
106
  try:
107
- # 1. Prepare a local copy to adjust configs
108
  model_dir = self.config.repo_path / "models" / input_model_id
109
  model_dir.mkdir(parents=True, exist_ok=True)
110
 
111
- # 2. Load and relocate generation parameters
112
  config = AutoConfig.from_pretrained(input_model_id)
113
  gen_cfg = GenerationConfig.from_model_config(config)
114
  for key in gen_cfg.to_dict().keys():
@@ -117,9 +117,10 @@ class ModelConverter:
117
  config.save_pretrained(model_dir)
118
  gen_cfg.save_pretrained(model_dir)
119
 
120
- # 3. Build and run the conversion command
121
  cmd = [
122
  sys.executable,
 
123
  "-m", "scripts.convert",
124
  "--quantize",
125
  "--trust_remote_code",
@@ -134,13 +135,15 @@ class ModelConverter:
134
  env=os.environ.copy(),
135
  )
136
 
137
- # 4. Filter out the relocation warning from stderr
138
- filtered_lines = [
139
- ln
140
- for ln in result.stderr.splitlines()
141
- if not ln.startswith("Moving the following attributes")
142
- ]
143
- stderr = "\n".join(filtered_lines)
 
 
144
 
145
  if result.returncode != 0:
146
  return False, stderr
@@ -254,5 +257,4 @@ def main():
254
 
255
 
256
  if __name__ == "__main__":
257
- main()
258
-
 
13
  from torch.jit import TracerWarning
14
  from transformers import AutoConfig, GenerationConfig
15
 
16
+ # Suppress TorchScript tracer warnings in parent process
17
  warnings.filterwarnings("ignore", category=TracerWarning)
18
 
19
  logging.basicConfig(level=logging.INFO)
 
100
  def convert_model(self, input_model_id: str) -> Tuple[bool, Optional[str]]:
101
  """
102
  Convert the model to ONNX format, always exporting attention maps.
103
+ Relocate generation parameters and suppress warnings in subprocess.
104
+ Strip out static relocation and tracer warnings from stderr.
105
  """
106
  try:
107
+ # Prepare local model folder for config edits
108
  model_dir = self.config.repo_path / "models" / input_model_id
109
  model_dir.mkdir(parents=True, exist_ok=True)
110
 
111
+ # Reload and relocate generation parameters
112
  config = AutoConfig.from_pretrained(input_model_id)
113
  gen_cfg = GenerationConfig.from_model_config(config)
114
  for key in gen_cfg.to_dict().keys():
 
117
  config.save_pretrained(model_dir)
118
  gen_cfg.save_pretrained(model_dir)
119
 
120
+ # Build command with warning suppression flag
121
  cmd = [
122
  sys.executable,
123
+ "-W", "ignore::torch.jit.TracerWarning",
124
  "-m", "scripts.convert",
125
  "--quantize",
126
  "--trust_remote_code",
 
135
  env=os.environ.copy(),
136
  )
137
 
138
+ # Filter stderr lines
139
+ filtered = []
140
+ for ln in result.stderr.splitlines():
141
+ if ln.startswith("Moving the following attributes"): # relocation warning
142
+ continue
143
+ if "TracerWarning" in ln: # any tracer warnings
144
+ continue
145
+ filtered.append(ln)
146
+ stderr = "\n".join(filtered)
147
 
148
  if result.returncode != 0:
149
  return False, stderr
 
257
 
258
 
259
  if __name__ == "__main__":
260
+ main()