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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -100,25 +100,24 @@ 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
- Also relocate any generation parameters into generation_config.json
104
- and suppress JIT tracer warnings.
105
  """
106
  try:
107
- # 1. Clone or prepare a local copy of the model 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
- # Remove generation-specific keys from model config
115
  for key in gen_cfg.to_dict().keys():
116
  if hasattr(config, key):
117
  setattr(config, key, None)
118
  config.save_pretrained(model_dir)
119
  gen_cfg.save_pretrained(model_dir)
120
 
121
- # 3. Build the conversion command
122
  cmd = [
123
  sys.executable,
124
  "-m", "scripts.convert",
@@ -127,8 +126,6 @@ class ModelConverter:
127
  "--model_id", input_model_id,
128
  "--output_attentions",
129
  ]
130
-
131
- # 4. Run the conversion
132
  result = subprocess.run(
133
  cmd,
134
  cwd=self.config.repo_path,
@@ -137,10 +134,18 @@ class ModelConverter:
137
  env=os.environ.copy(),
138
  )
139
 
 
 
 
 
 
 
 
 
140
  if result.returncode != 0:
141
- return False, result.stderr
142
 
143
- return True, result.stderr
144
 
145
  except Exception as e:
146
  return False, str(e)
@@ -250,3 +255,4 @@ def main():
250
 
251
  if __name__ == "__main__":
252
  main()
 
 
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():
115
  if hasattr(config, key):
116
  setattr(config, key, None)
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",
 
126
  "--model_id", input_model_id,
127
  "--output_attentions",
128
  ]
 
 
129
  result = subprocess.run(
130
  cmd,
131
  cwd=self.config.repo_path,
 
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
147
 
148
+ return True, stderr
149
 
150
  except Exception as e:
151
  return False, str(e)
 
255
 
256
  if __name__ == "__main__":
257
  main()
258
+