Skip to content

[Core ML] Improve error logging #9801

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

Merged
merged 3 commits into from
Apr 15, 2025

Conversation

cymbalrush
Copy link
Contributor

Summary

Fixes error logging.

  • The error message was getting ignored when logging to ET_LOG
  • If the compiled asset was corrupted then the init failed
  • Fixed header includes

Test plan

  • Unit tests
  • Manually deleted the cached asset and verified the init succeeded and the error message was logged.
ExecuTorch: Verifying mv3 model
I 00:00:00.119292 executorch:ETCoreMLModelManager.mm:461] Cache Hit: Successfully retrieved model with identifier=executorch_320d2b91-e091-4f92-9d4f-30b0d9eca1da_all from the models cache.
I 00:00:00.548662 executorch:main.mm:373] Load duration = 430.172000
I 00:00:00.548677 executorch:main.mm:376] Running method = forward
I 00:00:00.551965 executorch:main.mm:379] Inputs prepared.
I 00:00:00.552874 executorch:main.mm:385] Model executed successfully.
I 00:00:00.552878 executorch:main.mm:388] Inference latency=0.90ms.

Copy link

pytorch-bot bot commented Apr 1, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/9801

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 2 Pending

As of commit 6c1f90d with merge base c178637 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 1, 2025
@facebook-github-bot
Copy link
Contributor

@shoumikhin has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@shoumikhin
Copy link
Contributor

@pytorchbot label "topic: not user facing"

Comment on lines 8 to 17
#import "ETCoreMLAssetManager.h"
#import <ETCoreMLAsset.h>
#import <ETCoreMLLogging.h>
#import <database.hpp>
#import "ETCoreMLAsset.h"
#import "ETCoreMLLogging.h"
#import "database.hpp"
#import <iostream>
#import <json_key_value_store.hpp>
#import <serde_json.h>
#import "json_key_value_store.hpp"
#import "serde_json.h"
#import <sstream>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we group the imports by type?

#import "ETCoreMLAssetManager.h"

#import "ETCoreMLAsset.h"
#import "ETCoreMLLogging.h"

#import "database.hpp"
#import "json_key_value_store.hpp"
#import "serde_json.h"

#import <iostream>
#import <sstream>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@facebook-github-bot
Copy link
Contributor

@shoumikhin has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link

pytorch-bot bot commented Apr 1, 2025

To add the ciflow label ciflow/trunk please first approve the workflows that are awaiting approval (scroll to the bottom of this page).

This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. Please ping one of the reviewers if you do not have access to approve and run workflows.

@pytorch-bot pytorch-bot bot removed the ciflow/trunk label Apr 1, 2025
@metascroy
Copy link
Contributor

Looks great! Thanks for the PR.

I added ci/trunk to run our mac jobs in CI.

@cymbalrush do you know if the tests in backends/apple/coreml/runtime/test run in our CI? If not, are you running them locally?

Copy link

pytorch-bot bot commented Apr 1, 2025

To add the ciflow label ciflow/trunk please first approve the workflows that are awaiting approval (scroll to the bottom of this page).

This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. Please ping one of the reviewers if you do not have access to approve and run workflows.

@pytorch-bot pytorch-bot bot removed the ciflow/trunk label Apr 1, 2025
@cymbalrush
Copy link
Contributor Author

Looks great! Thanks for the PR.

I added ci/trunk to run our mac jobs in CI.

@cymbalrush do you know if the tests in backends/apple/coreml/runtime/test run in our CI? If not, are you running them locally?

Yes they are part of the CI. I ran them locally also.

@metascroy
Copy link
Contributor

@cymbalrush looks like there are some CI failures. Can you also run the lintrunner? (Once dev-requirements are installed, you can run lintrunner -a from executorch).

@cymbalrush cymbalrush force-pushed the fix_logging branch 2 times, most recently from 8ad1594 to 9d8e1be Compare April 3, 2025 15:03
@cymbalrush
Copy link
Contributor Author

@cymbalrush looks like there are some CI failures. Can you also run the lintrunner? (Once dev-requirements are installed, you can run lintrunner -a from executorch).

Ran lintrunner and fixed the failure.

@metascroy
Copy link
Contributor

@cymbalrush looks like there are some CI failures. Can you also run the lintrunner? (Once dev-requirements are installed, you can run lintrunner -a from executorch).

Ran lintrunner and fixed the failure.

Re-running CI

@facebook-github-bot
Copy link
Contributor

@shoumikhin has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@shoumikhin has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@shoumikhin
Copy link
Contributor

@cymbalrush it doesn't seem related to your change though.

@cymbalrush
Copy link
Contributor Author

@cymbalrush it doesn't seem related to your change though.

Yes, it's not related to the change.


#if ET_LOG_ENABLED
#define ETCoreMLLogInfo(formatString, ...) \
ET_LOG(Info, "%s", [NSString stringWithFormat:formatString, ##__VA_ARGS__].UTF8String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ET_LOG(Info, "%s", [NSString stringWithFormat:formatString, ##__VA_ARGS__].UTF8String)
ET_LOG(Info, "%s", [NSString stringWithFormat:@formatString, ##__VA_ARGS__].UTF8String)

Copy link
Contributor

@shoumikhin shoumikhin Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cymbalrush here's the root cause

@metascroy
Copy link
Contributor

@cymbalrush there are a lot of CI failures, e.g., in unittest / macos / macos-job:

/Users/ec2-user/runner/_work/executorch/executorch/pytorch/executorch/backends/apple/coreml/runtime/delegate/ETCoreMLModelManager.mm:528:21: error: string literal must be prefixed by '@'
2025-04-04T22:50:43.8379490Z       ETCoreMLLogInfo("Cache Miss: Model with identifier=%@ was not found in the models cache.", identifier);
2025-04-04T22:50:43.8379880Z                       ^

@cymbalrush
Copy link
Contributor Author

@cymbalrush there are a lot of CI failures, e.g., in unittest / macos / macos-job:

/Users/ec2-user/runner/_work/executorch/executorch/pytorch/executorch/backends/apple/coreml/runtime/delegate/ETCoreMLModelManager.mm:528:21: error: string literal must be prefixed by '@'
2025-04-04T22:50:43.8379490Z       ETCoreMLLogInfo("Cache Miss: Model with identifier=%@ was not found in the models cache.", identifier);
2025-04-04T22:50:43.8379880Z                       ^

@shoumikhin @metascroy Sorry I had the change in my local but it was not pushed. Should be fixed now.

@facebook-github-bot
Copy link
Contributor

@shoumikhin has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@metascroy
Copy link
Contributor

@cymbalrush there are a lot of CI failures, e.g., in unittest / macos / macos-job:

/Users/ec2-user/runner/_work/executorch/executorch/pytorch/executorch/backends/apple/coreml/runtime/delegate/ETCoreMLModelManager.mm:528:21: error: string literal must be prefixed by '@'
2025-04-04T22:50:43.8379490Z       ETCoreMLLogInfo("Cache Miss: Model with identifier=%@ was not found in the models cache.", identifier);
2025-04-04T22:50:43.8379880Z                       ^

@shoumikhin @metascroy Sorry I had the change in my local but it was not pushed. Should be fixed now.

Re-running CI

@facebook-github-bot
Copy link
Contributor

@metascroy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@metascroy
Copy link
Contributor

@cymbalrush there is one more CI failure in building the macOS wheels.

It is a linking issue in building coreml_executor_runner. You only changed the build type from Release to Debug, but maybe in conflicts with something in the coreml/workspace?

Separately, I'm not really sure why the coreml_executor_runner is being built as part of the executorch wheels. Maybe @jathu knows why?

@jathu
Copy link
Contributor

jathu commented Apr 10, 2025

@metascroy it's because we build the wheels, export a model using that wheel, then test the exported model with the coreml_executor_runner. If there is a build error, we need to fix it

"${PYTHON_EXECUTABLE}" -m examples.apple.coreml.scripts.export --model_name="${MODEL_NAME}" --compute_precision "${DTYPE}"
EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*.pte" -print -quit)
if [ -n "$EXPORTED_MODEL" ]; then
EXPORTED_MODEL_WITH_DTYPE="${EXPORTED_MODEL%.pte}_${DTYPE}.pte"
mv "$EXPORTED_MODEL" "$EXPORTED_MODEL_WITH_DTYPE"
EXPORTED_MODEL="$EXPORTED_MODEL_WITH_DTYPE"
echo "OK exported model: $EXPORTED_MODEL"
else
echo "[error] failed to export model: no .pte file found"
exit 1
fi
# Run the model
if [ "${should_test}" = true ]; then
echo "Installing requirements needed to build coreml_executor_runner..."
backends/apple/coreml/scripts/install_requirements.sh
echo "Testing exported model with coreml_executor_runner..."
local out_dir=$(mktemp -d)
COREML_EXECUTOR_RUNNER_OUT_DIR="${out_dir}" examples/apple/coreml/scripts/build_executor_runner.sh
"${out_dir}/coreml_executor_runner" --model_path "${EXPORTED_MODEL}"
fi

Signed-off-by: Gyanendra Sinha <[email protected]>

Address comments

Address comments
@cymbalrush
Copy link
Contributor Author

cymbalrush commented Apr 14, 2025

Updated to build for Release mode by default and added an option to build for Debug mode.

@facebook-github-bot
Copy link
Contributor

@metascroy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@metascroy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@metascroy
Copy link
Contributor

Landing from phabricator

@facebook-github-bot facebook-github-bot merged commit 1bf3cf5 into pytorch:main Apr 15, 2025
97 checks passed
keyprocedure pushed a commit to keyprocedure/executorch that referenced this pull request Apr 21, 2025
Differential Revision: D72251859

Pull Request resolved: pytorch#9801
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants