WWDC24ï¼æ©æ¢°å¦ç¿ã¨AIã¢ãã«ãAppleã·ãªã³ã³ã«çµ±å
â»æ¬ãµã¤ãã¯ãã¢ãã£ãªã¨ã¤ãåºåããã³åºåã«ããåçãå¾ã¦éå¶ãã¦ãã¾ããè³¼å ¥ã«ãã売ä¸ã®ä¸é¨ãæ¬ãµã¤ãã«éå ããããã¨ãããã¾ãã
AppleããWWDC24ã«ããã¦ãæ©æ¢°å¦ç¿ã¨AIã¢ãã«ãAppleã·ãªã³ã³ã«çµ±åããå ¬éãã¦ãã¾ãã
Appleã®Core MLãã¼ã ã®ã¨ã³ã¸ãã¢Qiqi Ziaoæ°ã¯ãCore ML Toolsã«å ããããããã¤ãã®ã¨ããµã¤ãã£ã³ã°ãªã¢ãããã¼ãã«ã¤ãã¦ã話ããã¾ãããããã®ã¢ãããã¼ãã¯ãæ©æ¢°å¦ç¿ãAIã®ã¢ãã«ãApple Siliconã§ããè¯ãæ´»ç¨ããã®ã«å½¹ç«ã¡ã¾ããã¢ãã«ãããã¤ã®ã¯ã¼ã¯ããã¼ã«ã¯3ã¤ã®éè¦ãªæ®µéãããã¾ãã
ç§ã¯æºå段éã«ç¦ç¹ãå½ã¦ãå¤ãã®æé©åãå ±æããããã¤ã¹ä¸ã§ã¢ãã«ãæãå¹ççã«å®è¡ããããã®æ©è½ãå«ã¾ãã¦ãããã¨ã確èªãã¾ãããã®ã»ãã·ã§ã³ã§ã¯ãããªãããã§ã«æ©æ¢°å¦ç¿ã¢ãã«ãæã£ã¦ããã¨ä»®å®ãã¾ãããã®ã¢ãã«ã¯ãäºåã«è¨ç·´ããããã®ã微調æ´ããããã®ããããã¯ã¼ãããè¨ç·´ããããã®ã§ããå¯è½æ§ãããã¾ãã
Core ML Toolsã¯ãªã¼ãã³ã½ã¼ã¹ã®Pythonããã±ã¼ã¸ã§ãAppleã®ãã¬ã¼ã ã¯ã¼ã¯ã§ä½¿ããããã«ã¢ãã«ãæé©åã»å¤æããã¦ã¼ãã£ãªãã£ãå«ã¾ãã¦ãã¾ãã
PyTorchï¼ãã¤ãã¼ãï¼ã§ä½æããã¢ãã«ãCore MLå½¢å¼ã«å¤æããApple Siliconã§ã®å®è¡ã«æé©åãããã¨ãã§ãã¾ãã
Apple Siliconã®çµ±åã¡ã¢ãªãCPUãGPUãNeural Engineã¯ãããã¤ã¹ä¸ã®æ©æ¢°å¦ç¿ã¯ã¼ã¯ãã¼ãã«ä½ã¬ã¤ãã³ã·ã¼ã¨å¹ççãªè¨ç®ãæä¾ãã¾ãã
ããã©ã«ãã§ã¯ãã¢ãã«ãCore MLãã©ã¼ãããã«å¤æããæ¨è«ã«Appleã®ãã¬ã¼ã ã¯ã¼ã¯ã使ç¨ããã ãã§ãã¢ããªã±ã¼ã·ã§ã³ã¯Apple Siliconã®ãã¯ã¼ãæ´»ç¨ã§ãã¾ãã
Apple Siliconã¯Appleã®ãã¹ã¦ã®ãã©ãããã©ã¼ã ã«å¯¾å¿ãã¦ãã¾ãããããããã«ç¬èªã®ç¹æ§ã¨å¼·ã¿ãããã¾ãã
ã¿ã¼ã²ããã¨ãããã©ãããã©ã¼ã ãããã¤ã¹ã§å©ç¨å¯è½ãªã¹ãã¬ã¼ã¸ãã¡ã¢ãªãã³ã³ãã¥ã¼ãã£ã³ã°ã®çµã¿åãããèæ ®ããå¿ è¦ãããã¾ãã
ãããã®å±æ§ã¯ãã¦ã¼ã¹ã±ã¼ã¹ã«å¿ è¦ãªã¢ãã«ã®ãµã¤ãºã精度ãã¬ã¤ãã³ã·ã¼ã«åãããå¿ è¦ãããã¾ãã
ã¢ãã«æºåã®ä¸ç°ã¨ãã¦ããªãã·ã§ã³ãæ¤è¨ããæ§ã ãªæé©åãé©ç¨ãã¦ãæé©ãªé ç½®ãè¦ã¤ãã¾ãããã®æ¹æ³ãä¸ç·ã«æ¢ã£ã¦ã¿ã¾ãããã
ã¾ããæ¨å¹´å°å ¥ãããã¦ã§ã¤ãå§ç¸®æè¡ãæ¯ãè¿ã£ã¦ã¿ãããæåã®ãã¯ããã¯ã¯palettizationã¨å¼ã°ãããã®ã§ããã¬ããåã§ã¯ãä¼¼ããããªå¤ãæã¤éã¿ã¯ã¯ã©ã¹ã¿åãããã¯ã©ã¹ã¿ã®ã»ã³ããã¤ãã®å¤ã使ã£ã¦è¡¨ç¾ããã¾ãã
ã¯ã©ã¹ã¿ã®ä¸å¿ã¯ã«ãã¯ã¢ãããã¼ãã«ã«æ ¼ç´ããã¾ããã«ãã¯ã¢ãããã¼ãã«ã¸ã®Nãããã®ã¤ã³ããã¯ã¹ããããå§ç¸®ãããéã¿ã«ãªãã¾ãã
ãã®ä¾ã§ã¯ãéã¿ã¯2ãããã«å§ç¸®ããã¦ãã¾ãã
2ã¤ç®ã®ææ³ã¯éååã¨å¼ã°ãããã®ã§ãã
éååãè¡ãã«ã¯ãæµ®åå°æ°ç¹æ°ï¼Floatï¼ã®ã¦ã§ã¤ãå¤ãæ´æ°ã®ç¯å²ã«ç·å½¢ããããã¾ãã
æ´æ°ã®ã¦ã§ã¤ãã¯ãéååãã©ã¡ã¼ã¿ã¨ãã¦ç¥ãããã¹ã±ã¼ã«ã¨ãã¤ã¢ã¹ã®ãã¢ã¨ã¨ãã«ä¿åãããå¾ã§æ´æ°ãããã¼ãã«æ»ãããã«ä½¿ç¨ã§ãã¾ãã
3ã¤ç®ã®ãã¯ããã¯ã¯ãã«ã¼ãã³ã°ã§ãããã«ã¼ãã³ã°ã¯ãã¢ãã«ã®éã¿ãã¹ãã¼ã¹è¡¨ç¾ã§å¹ççã«è©°ãè¾¼ãã®ã«å½¹ç«ã¡ã¾ãã
éã¿è¡åããå§ãã¦ãæå°ã®å¤ã0ã«è¨å®ãã¾ããããã§ãããããã¹ã¯ã¨0以å¤ã®å¤ã ããä¿åããã°ãããªãã¾ãã
æ¢åã®ãã¯ããã¯ã¯ãå¤ãã®ã¢ãã«ã§ãã¾ãæ©è½ãã¦ãã¾ããã§ã¯ããããã®ãã¯ããã¯ã®ããã¤ãã大ããªã¢ãã«ã«é©ç¨ããããã«å§ç¸®ããããã«ã©ã®ããã«æ¡å¼µããããè¦ã¦ã¿ããã
å®å®æ¡æ£ã¢ãã«ã®ä¾ã§ããããã¯ããã³ããã¨ãã¦ç¥ãããèªç¶è¨èªã®èª¬æãåãåãããã®èª¬æã«ä¸è´ããç»åãçæãã¾ãã
å¤æãã¦ã¿ãã¨ãä¸çªå¤§ããªã¢ãã«ã®ã¢ãã«ãµã¤ãºã¯Float16ã®ç²¾åº¦ã§5GBãè¶
ãã¦ãããã¨ããããã¾ãã
ããã¯å½åãiPhoneãiPadã§å®è¡ããã«ã¯å¤§ãããããã®ã¢ãã«ããããã¤ããã«ã¯ãå§ç¸®ããå¿
è¦ãããã¾ãã
å§ç¸®çãå¤ããããã«ãããæ°ãæè»ã«é¸æã§ãããã¬ããåã試ãã¦ã¿ã¾ãã
ä¾ãã°ã8ãããã®ãã¬ããåãé©ç¨ããã¨ãã¢ãã«ã®ãµã¤ãºãFloat16ã¢ãã«ã®ç´ååã«ãããã¨ãã§ãã¾ããç§ã®Macã§ã¯ãããã³ãããã¿ãã·ã¼ãã®ç«ããã£ã³ãã¹ã«æ²¹çµµãã§ç´ æ´ãããç»åãå¾ããã¨ãã§ãã¾ãã
ããããiPhoneãiOSã¨ã®çµ±åãèããåã«ããã®ã¢ãã«ã2GB以ä¸ã«ãããã6ããããªããã®æ¡ä»¶ãæºãããã¨ãã§ããæçµçã«iPadã§ãã®ã¢ãã«ãåãããã¨ãã§ãã¾ãã
4ãããã¯ã©ãã§ããï¼è¯ãç»åãå¾ãããªããªãã¾ãããã¤ã¾ããã¢ãã«ãæ£ç¢ºã§ãªããªã£ãã®ã§ãã
ã§ã¯ãããã§ä½ãèµ·ãã£ã¦ããã®ãï¼ããããç解ããããã«ã¯ãã¾ããã¬ãã¿ã¤ãºè¡¨ç¾ãè¦ç´ãå¿
è¦ãããã¾ãã
iOS 17ã¯ããã¹ã¦ã®å¤ãåä¸ã®ã«ãã¯ã¢ãããã¼ãã«ã«ã¯ã©ã¹ã¿åããããã³ã½ã«ãã¨ã®ãã¬ãã¿ã¤ãºã®ã¿ããµãã¼ããã¦ãã¾ããã4ãããã»ãã¬ã¿ã¤ãºã使ç¨ãããå ´åããã³ã½ã«å ¨ä½ã«ãããããã¯ããã¯ã©ã¹ã¿ã»ã»ã³ããã¤ãã¯16åããããã¾ãããããã¯ç²åº¦ãå°ããããã大ããªè¡åã§ã¯æ½å¨çãªã¨ã©ã¼ãçºçãããããªãã¾ãã
ã§ã¯ãã©ã®ããã«ç²åº¦ãä¸ããããèãã¦ã¿ã¾ãã
ä¸æ©ä¸ãã£ã¦ãæ©æ¢°å¦ç¿ã®åéã§ãã使ãããç¨èªãããã¤ã説æãã¾ãã
éã¿ã¯è¡åã§è¡¨ããã¨ãã§ããããã§ã¯è¡åã®è¡ã§åºåãã£ã³ãã«ããåã§å ¥åãã£ã³ãã«ã表ãã¦ãã¾ãã
ãã³ã½ã«å ¨ä½ã«å§ç¸®ãé©ç¨ãããã¨ãã§ããããåãã£ã³ãã«ã»ã°ã«ã¼ãããããã¯åãã£ã³ãã«ã«åå¥ã«å§ç¸®ãé©ç¨ãããã¨ãã§ãã¾ãã
ããããã®è¡ãå°ããªãããã¯ã«åå²ãããµããã£ã³ãã«ã¬ãã«ã§å§ç¸®ãããããã¨ãã§ãã¾ãã
å³ã®å·¦ããå³ã«åãã£ã¦ãç²åº¦ã¯å¾ã ã«å¤§ãããªã£ã¦ããã¾ãã
Palettizationã«è©±ãæ»ãã¨ãiOS 17ã§ã¯ãã«ã»ã¦ã§ã¤ãã»ãã³ã½ã«ã«1ã¤ã®ã«ãã¯ã¢ãããã¼ãã«ãå²ãå½ã¦ããã¨ãã§ãã¾ããããiOS 18ã§ã¯è¤æ°ã®ã«ãã¯ã¢ãããã¼ãã«ãæ ¼ç´ã§ããããã«ãªãã¾ãããããã«ãããã¯ããã«åªãã精度ãéæã§ãã¾ãã
ç·å½¢éååã«ã¤ãã¦ã¯ãiOS 17ã§ã¯ãã£ã³ãã«ãã¨ã«ã¹ã±ã¼ã«ã¨ãã¤ã¢ã¹ãè¨å®ã§ãã¾ããããiOS 18ã§ã¯ãããã®éååãã©ã¡ã¼ã¿ããããã¯ãã¨ã«è¨å®ã§ããããã«ãªãã¾ããã
ãã«ã¼ãã³ã°æè¡ã«ã¤ãã¦ããããã«å§ç¸®ã§ããããã«ãªãã¾ããã以åã¯ãå¯ãªã¦ã§ã¤ããFloat精度ã®éã¼ãå¤ã«ã¹ãã¼ã¹ããã¦ãã¾ããã
ãã®æµ®åå°æ°ç¹ã®éã¼ãå¤ã¯ãPalettizationãéååã使ã£ã¦ããã«å§ç¸®ãããã¨ãã§ãã¾ãã
2ã¤ã®ç°ãªãå§ç¸®æè¡ã®ç¹å¾´ãåæã«å©ç¨ãããã¨ãã§ããããã«ãªããã¹ãã¼ã¹ãã¬ããåã¨ã¹ãã¼ã¹éååãå¯è½ã«ãªã£ãã®ã§ãã
ãã®ã¢ãã«ã®ããã©ã¼ãã³ã¹ãè¦ã¦ã¿ã¾ãã
group_size 16ã§ãç§ã®ããã³ããã«ãããããå¥ã®ç«ãè¦ãã¾ãããã®çæãããç»åã¯ä»¥åãããã£ã¨è¯ããªã£ã¦ãã¾ãã
ã¤ã¾ãã1.29GBãã1.3GBã¸ã¨ãµã¤ãºããããããã«å¢ããã ãã§ã精度ã®ã»ã¨ãã©ãåãæ»ããã¨ãã§ãã¾ããã
ãã®å¢å ã¯ã追å ãããã«ãã¯ã¢ãããã¼ãã«ã«ãã£ã¦ä½åãªå®¹éãå°ãå¢ããããã§ãã
ã¾ã¨ããã¨ãiOS 18ã§ã¯ãã°ã«ã¼ãåããããã£ã³ãã«ãã¨ã®ãã¬ã¿ã¤ãºã¯ãè¤æ°ã®ã«ãã¯ã¢ãããã¼ãã«ãæã¤ãã¨ã«ãã£ã¦ç²åº¦ãå¢å ããã¾ãã
ããã¯ãã¥ã¼ã©ã«ã»ã¨ã³ã¸ã³ãæè¼ããApple Siliconã§è¼ããæ¾ã¡ã¾ãããããã¯ãã¨ã®éååã«å ãã¦ã8ããããã4ãããéååããµãã¼ãããããã«ãªãã¾ããã
ãã®ã¢ã¼ãã¯ç¹ã«Macã®GPUã«æé©åããã¦ãã¾ãã
æå¾ã«ãã¹ãã¼ã¹æ§ãä»ã®å§ç¸®ã¢ã¼ãã¨çµã¿åããããã¨ãã§ããããã«ãªãã¾ããã
ã¢ãã«å§ç¸®ã«ã¤ãã¦çµè«ä»ããåã«ãå§ç¸®ã¯ã¼ã¯ããã¼ã«ã¤ãã¦èª¬æãã¾ãã
ããã¾ã§ã®ã¨ãããå§ç¸®ã«ä½¿ç¨ãã¦ããã¯ã¼ã¯ããã¼ã¯ããã¹ããã¬ã¼ãã³ã°ã¢ããã¼ãã§ããããã¯äºåã«ãã¬ã¼ãã³ã°ãããCore MLã¢ãã«ããå§ã¾ããé常ã«ä¾¿å©ãªæ¹æ³ã§ãã¼ã¿ãªãã§å§ç¸®ããã¾ãã
ãããããã®ãã¼ã¿ããªã¼ã®ã¯ã¼ã¯ããã¼ã¯ã精度ã¨å§ç¸®éã®æé©ãªãã¬ã¼ããªãããããããªãããããã¾ãããå§ç¸®çãé«ããªãã¨ã精度ãæ¥éã«ä½ä¸ãã¾ãã
ãããåé¿ãã1ã¤ã®æ¹æ³ã¯ãå¦ç¿æéå§ç¸®ã使ç¨ãããã¨ã§ãã
éã¿ãå§ç¸®ããªãããPyTorchã¢ãã«ãå¦ç¿ãã¼ã¿ã§å¾®èª¿æ´ãããã¨ãã§ãã¾ããããã¦ãããCore MLå½¢å¼ã«å¤æãã¾ãã
ããã«ãããããæ£ç¢ºãªã¢ãã«ãå¾ããã¨ãã§ãã¾ããããã®ããã»ã¹ã¯æéããããã大è¦æ¨¡ãªã¢ãã«ã§ã¯ãã¼ã¿ãæ¶è²»ãã¾ãã
ããã§ãæ°ããã¯ã¼ã¯ããã¼ããç´¹ä»ãã¾ããããã¯ããã£ãªãã¬ã¼ã·ã§ã³ãã¼ã¿ã使ã£ããã¹ããã¬ã¼ãã³ã°å§ç¸®ã§ãã
ããã¯ããã¼ã¿ããªã¼ã¢ããã¼ãã¨ãã¡ã¤ã³ãã¥ã¼ãã³ã°ã¢ããã¼ãã®ä¸éã®ãã¬ã¼ããªããæä¾ãã¾ãã
ãã®å ´åãã¢ãã«å§ç¸®ã®ãã£ãªãã¬ã¼ã·ã§ã³ã«å¿ è¦ãªãã¼ã¿éã¯éããã¦ãã¾ãã微調æ´ã¯ã¾ã£ããå¿ è¦ãªããããã»ããã¢ãããç°¡åã§ãæéããããã¾ããã
ä»å¹´coremltools.optimizeã«å°å ¥ãããæ°ããAPIã使ãã°ããã®ã¯ã¼ã¯ããã¼ãé常ã«ç°¡åã«å®è¡ã§ãã¾ãã
ã¹ãã¼ã¹ã¢ãã«ãCore MLå½¢å¼ã«å¤æãããã¨ãã§ãã¾ãããã¹ãã¼ã¹ãã¬ã¿ã¤ã¼ã¼ã·ã§ã³ãå¯è½ãªã®ã§ããã«ã¼ãã³ã°ã®å¾ã«ãã¬ã¿ã¤ã¼ã¼ã·ã§ã³ãè¡ããããã«å§ç¸®ãããã¨ãã§ãã¾ãã
ã¹ãã¼ã¹ã¡ã¿ãã¼ã¿æ
å ±ã渡ãããã«ãåååå¾ããã¹ãã¼ã¹ã¢ãã«ã使ç¨ãã¾ããããã§ããå¿
è¦ãªã¢ã¸ã¥ã¼ã«ãã¤ã³ãã¼ããããã¬ããåã®è¨å®ãè¡ãã¾ããããã§ã¯ã4ãããç²åº¦ã "per_grouped_channel "ã«ãgroup_sizeã16ã«è¨å®ãã¾ããã
PostTrainingPalettizerãªãã¸ã§ã¯ããä½æããpalettizer.compressã§sparse_palettized_modelãåå¾ãã¾ãããã®PyTorchã¢ãã«ã¯ã·ã¼ã ã¬ã¹ã«Core MLå½¢å¼ã«å¤æãããã¨ãã§ãã¾ãã
40%ã®ã¹ãã¼ã¹æ§ãé©ç¨ããå¾ãå®å®ããæ¡æ£ã¢ãã«ã®ãµã¤ãºã¯ããã«1.1GBã«ç¸®å°ããã¾ãã
ãã¼ã¿ããªã¼ã®ãã¹ããã¬ã¼ãã³ã°å§ç¸®ã§ã¯ãã¢ãã«ã¯ãã¤ãºåºåããã§ãã¾ãããããã¼ã¿ãã£ãªãã¬ã¼ã·ã§ã³ã¯ã¼ã¯ããã¼ã§ã¯ãã¢ãã«ã¯å¥ã®ç«ç»åãçæã§ãã¾ãã
ãã£ãªãã¬ã¼ã·ã§ã³ã«åºã¥ãã¯ã¼ã¯ããã¼ã¯ãã¾ãæ©è½ãã¦ãã¾ãã
ã¾ã¨ããã¨ãCore ML Tools 8ã§ã¯ãæ°ããå§ç¸®è¡¨ç¾ã試ããã¨ãã§ãã¾ãã
ã¾ãããã£ãªãã¬ã¼ã·ã§ã³ãã¼ã¿ã使ç¨ããæ°ããå§ç¸®ã¯ã¼ã¯ããã¼ã使ç¨ã§ãã¾ãã