Only validate on macOS.
Browse files5 unmodified lines67891011143 unmodified lines15515615715815916016116216316411 unmodified lines17617717817918018118218365 unmodified lines2492502512522532542552565 unmodified linesfrom huggingface_hub import hf_hub_download, HfApifrom coremltools import ComputeUnitfrom transformers.onnx.utils import get_preprocessorfrom exporters.coreml import export143 unmodified linesmlmodel.save(filename)progress(progress_end * 0.8, desc=f"Validating {model_label}")if tolerance is None:tolerance = coreml_config.atol_for_validationvalidate_model_outputs(coreml_config, preprocessor, model, mlmodel, tolerance)progress(progress_end, desc=f"Done converting {model_label}")11 unmodified lines)subprocess.run(["rm", "-rf", directory])return f"""Successfully converted! We opened a PR to add the Core ML weights to the model repo.Please, view and merge the PR [here]({get_pr_url(HfApi(token=token), destination, commit_message)})."""def convert(model_id, task,65 unmodified lines)progress(0.7, "Uploading model to Hub")result = push_to_hub(destination_model, base, task, precision, token=token)progress(1, "Done")return resultexcept Exception as e:return error_str(e, model=model_id, task=task, framework=framework, compute_units=compute_units, precision=precision, tolerance=tolerance)5 unmodified lines678910111213143 unmodified lines15715815916016116216316416516616711 unmodified lines17918018118218318418565 unmodified lines2512522532542552562572582592602612622632642652665 unmodified linesfrom huggingface_hub import hf_hub_download, HfApifrom coremltools import ComputeUnitfrom coremltools.models.utils import _is_macos, _macos_versionfrom transformers.onnx.utils import get_preprocessorfrom exporters.coreml import export143 unmodified linesmlmodel.save(filename)if _is_macos() and _macos_version() >= (12, 0):progress(progress_end * 0.8, desc=f"Validating {model_label}")if tolerance is None:tolerance = coreml_config.atol_for_validationvalidate_model_outputs(coreml_config, preprocessor, model, mlmodel, tolerance)progress(progress_end, desc=f"Done converting {model_label}")11 unmodified lines)subprocess.run(["rm", "-rf", directory])return get_pr_url(HfApi(token=token), destination, commit_message)def convert(model_id, task,65 unmodified lines)progress(0.7, "Uploading model to Hub")pr_url = push_to_hub(destination_model, base, task, precision, token=token)progress(1, "Done")did_validate = _is_macos() and _macos_version() >= (12, 0)result = f"""### Successfully converted!We opened a PR to add the Core ML weights to the model repo. Please, view and merge the PR [here]({pr_url}).{f"**Note**: model could not be automatically validated as this Space is not running on macOS." if not did_validate else ""}"""return resultexcept Exception as e:return error_str(e, model=model_id, task=task, framework=framework, compute_units=compute_units, precision=precision, tolerance=tolerance)
app.py+17-7