feat: Add InsightFace/PuLID support on macOS Apple Silicon#14
feat: Add InsightFace/PuLID support on macOS Apple Silicon#14jamesbrink merged 2 commits intomainfrom
Conversation
Closes #13 This PR enables InsightFace and PuLID custom node support on macOS Apple Silicon by removing the MXNet dependency and using ONNX Runtime instead. ## Changes ### InsightFace without MXNet (`nix/python-overrides.nix`) - Override insightface package to remove mxnet from dependencies - MXNet was only used for one legacy CLI command (rec_add_mask_param.py) - Face analysis uses ONNX Runtime which works on all platforms - Added platforms = lib.platforms.unix to meta ### FaceXLib Nix Store Fix (`nix/python-overrides.nix`) - Patched facexlib wheel to respect FACEXLIB_MODELPATH environment variable - This redirects model downloads away from the read-only Nix store - Models now download to user's data directory on first use ### Cross-Platform PuLID (`nix/packages.nix`, `nix/custom-nodes.nix`) - Enabled insightface and facexlib packages on all platforms (not just Linux) - Updated launcher to link PuLID custom node on macOS - Added environment variables for model cache directories: - TORCH_HOME -> $BASE_DIR/.cache/torch - HF_HOME -> $BASE_DIR/.cache/huggingface - FACEXLIB_MODELPATH -> $BASE_DIR/.cache/facexlib - Added facexlib to PuLID's pythonDeps ### Documentation (`docs/pulid-setup.md`) - Added comprehensive PuLID setup guide - Documents required models and download locations - Explains auto-downloaded models and cache directories - Includes troubleshooting section ### Helper Script (`scripts/download-pulid-models.sh`) - Standalone script to download PuLID and InsightFace models - Supports custom data directory argument - Skips already-downloaded models ## Technical Details - InsightFace 0.7.3 uses ONNX Runtime for inference (not MXNet) - PuLID supports CoreML provider selection for macOS acceleration - Current onnxruntime provides CPUExecutionProvider; CoreML can be added later - FaceXLib models download on first use to the facexlib cache directory ## Testing Verified on macOS Apple Silicon (aarch64-darwin): - Build succeeds - All flake checks pass - InsightFace imports and FaceAnalysis works - FaceXLib models download to correct location - PuLID workflow executes successfully
Code Review: InsightFace/PuLID macOS Apple Silicon SupportOverall, this is a well-implemented PR that successfully enables cross-platform support for face analysis features. The approach is technically sound and follows Nix best practices. I have a few suggestions for improvement: ✅ Strengths
🔍 Issues & Suggestions1. Security: Unverified Model Downloads (Medium Priority)Location: The script downloads models without checksum verification: curl -L "$PULID_URL" -o "$PULID_MODEL" --progress-barRecommendation: Add SHA256 checksum verification after downloads to prevent supply chain attacks: PULID_SHA256="expected_hash_here"
curl -L "$PULID_URL" -o "$PULID_MODEL" --progress-bar
# Verify checksum
if command -v sha256sum &> /dev/null; then
echo "$PULID_SHA256 $PULID_MODEL" | sha256sum -c - || error "Checksum verification failed"
elif command -v shasum &> /dev/null; then
echo "$PULID_SHA256 $PULID_MODEL" | shasum -a 256 -c - || error "Checksum verification failed"
fi2. Potential Regex Issue in sed Pattern (Low Priority)Location: The sed -i 's|^ROOT_DIR = os.path.dirname.*|_DEFAULT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))\nROOT_DIR = os.environ.get("FACEXLIB_MODELPATH", _DEFAULT_ROOT)|' "$miscPy"Issues:
Recommendation: Either use postInstall = ''
miscPy="$out/${final.python.sitePackages}/facexlib/utils/misc.py"
if [[ -f "$miscPy" ]]; then
sed -i.bak 's|^ROOT_DIR = os.path.dirname.*|_DEFAULT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))\nROOT_DIR = os.environ.get("FACEXLIB_MODELPATH", _DEFAULT_ROOT)|' "$miscPy"
if ! grep -q "FACEXLIB_MODELPATH" "$miscPy"; then
echo "ERROR: Failed to patch facexlib misc.py" >&2
exit 1
fi
rm "$miscPy.bak"
fi
'';3. Missing Test for insightface Override (Medium Priority)Location: The insightface override filters out mxnet but doesn't verify the filtering worked correctly. Recommendation: Add a build-time check: insightface = prev.insightface.overridePythonAttrs (old: {
dependencies = builtins.filter (dep: dep.pname or "" != "mxnet") (old.dependencies or [ ]);
disabledTests = (old.disabledTests or [ ]) ++ [
"test_cli"
];
# Verify mxnet was actually removed
postInstall = (old.postInstall or "") + ''
# Check that mxnet isn't in the package metadata
if grep -q "mxnet" "$out/${final.python.sitePackages}/insightface-"*.dist-info/METADATA 2>/dev/null; then
echo "ERROR: mxnet still present in insightface metadata" >&2
exit 1
fi
'';
pythonImportsCheck = [
"insightface"
"insightface.app"
"insightface.model_zoo"
];
meta = (old.meta or { }) // {
platforms = lib.platforms.unix;
};
});4. Directory Creation Race Condition (Low Priority)Location: export FACEXLIB_MODELPATH="$BASE_DIR/.cache/facexlib"
mkdir -p "$FACEXLIB_MODELPATH/facexlib/weights"Creating the nested directory structure with the specific subdirectory is good, but the path structure seems to duplicate "facexlib" ( Question: Is this intentional based on how facexlib expects the path? If not, consider: export FACEXLIB_MODELPATH="$BASE_DIR/.cache/facexlib"
mkdir -p "$FACEXLIB_MODELPATH/weights"5. Documentation: License Clarity (Low Priority)Location: | AntelopeV2 | [MonsterMMORPG/tools](https://huggingface.co/MonsterMMORPG/tools) | Non-commercial |The "Non-commercial" license should be verified and more specific. Some users may need to know the exact license terms. Recommendation: Add a note about verifying license compatibility for commercial use. 🧪 Test CoverageThe PR description mentions:
Suggestion: Consider adding these as automated checks if possible, especially for the import test. 📝 Code StyleThe code follows the project's style guidelines well:
🎯 SummaryRecommendation: Approve with minor suggestions This PR successfully achieves its goal of enabling InsightFace/PuLID on macOS Apple Silicon. The core implementation is sound. The suggestions above are mostly defensive improvements around:
None of these are blocking issues, but addressing them would make the implementation more production-ready. Priority fixes (if any):
Great work on this cross-platform enablement! 🎉 |
Add -h/--help flag support showing usage, options, examples, and download sizes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code Review: InsightFace/PuLID macOS Apple Silicon SupportSummaryThis PR successfully enables InsightFace and PuLID custom nodes on macOS Apple Silicon by removing the MXNet dependency and using ONNX Runtime. The implementation is well-designed and follows Nix best practices. Strengths1. Excellent Technical Approach ✅
2. Clean Code Quality ✅
3. Excellent Documentation ✅
4. User-Friendly Tooling ✅
Issues & Recommendations1. Security: facexlib Patch Robustness
|
Summary
Closes #13
This PR enables InsightFace and PuLID custom node support on macOS Apple Silicon by removing the MXNet dependency and using ONNX Runtime instead.
FACEXLIB_MODELPATHenv var for Nix store compatibilityChanges
nix/python-overrides.nixnix/packages.nixnix/custom-nodes.nixdocs/pulid-setup.mdscripts/download-pulid-models.shTechnical Approach
InsightFace without MXNet: The nixpkgs insightface package depends on mxnet, which is Linux-only. However, mxnet is only used for one legacy CLI command - face analysis uses ONNX Runtime. We override insightface to filter out the mxnet dependency.
FaceXLib Nix Store Fix: FaceXLib tries to download models to its package directory (read-only in Nix). We patch it via
postInstallsed to checkFACEXLIB_MODELPATHenvironment variable, which the launcher sets to$BASE_DIR/.cache/facexlib.Cache Directory Redirection: The launcher now sets
TORCH_HOME,HF_HOME, andFACEXLIB_MODELPATHto redirect all model downloads to the user's data directory.Test plan