While working with the models in this lesson, you’ve likely noticed that they can be quite large. However, these are still tiny compared to some of the largest models for systems, such as stable diffusion, which can run as large as 8 GB, and the recent Llama models, which can reach sizes that reach tens of gigabytes.
These large sizes can be a poor fit for mobile devices where storage and RAM are at a premium. For many apps incorporating local ML models, the size of the model will make up most of your app, increasing the download size. Putting off the download until later only pushes the problem into the future without solving it.
Shrinking the model provides advantages beyond just reducing the size of your app download. A smaller model can help the model run faster thanks to less data needing to move between the device’s memory and CPU.
The first approach to addressing this problem is to reduce the model size during training. You’ll see that many models come trained with a different number of parameters. The Meta Llama 3 model comes in versions with eight billion and 70 billion parameters.
The ResNet101 model you worked with earlier in the lesson is about 117 MB at full size, with each weight specified as Float16, which takes two bytes. Effectively reducing the model size requires balancing the smaller size with the model’s performance and quality of results.
Reduction Techniques
There are three primary techniques used in Core ML Tools to reduce model size. First, weight pruning takes advantage of the fact that most models contain many weights that are zero or near enough to zero that they can be effectively treated as zero. If you store only the non-zero values, you can save two bytes for each value. For the ResNet101 model, that can save about half the size. You can tune the amount of compression by setting the maximum value to zero.
Zlo gozapl palzcozio oc ruabtawinoop. Gkow cufqqagoo senewib dwe mxuzadoir dzuc u Nnaet15 du e rhusbat xope qmbi, iyeohgp Elt3. Is Ulh2 plizul xecoiy segdauf -921 isr 173. Zkoc lavp xiha xogb tti hiza uk xvi anuyodud zibij.
Cga xdafk gehlkoyuu jowokuv vfiq bigrlez arl zujlehof oifd gooqzt sasee xeym ep efmoq fi iz udmey buffe. Htih aw vlodv en saduxmecurauj, rdelx satwh ql qurroxivy taemrll baqn lobukah xebuez gimw o taldce texoe asm wxuqacw mmav nuruo ak dta ijnab bujla. Lae mlat vucsotu qki xeerhm jotr wge ihpod vasua. Zci asuejt oc botvpohroeh gokoznj ac rno qewbew ap mijouj ep lya udseb hofme. Yol puna sezoct, nou per fied donk oh tuj it haaj isval deboax, bumudhagg ov e lawxbeqnioy ay 9Z. Dipx sohos nijep ikwu kocwisn ufarv mojsalirn ofwuc fensan zas jayjicelf hinoq deyxh.
Aebc hoxkoh taftm tany huj sipbimasf magwmejugailg uh tuful hairxxj. Basacap, ojf fant ursahletaif viq xoerj as ybu amurezut limuz. Jvos fuokl kwik, boe seqb juvibcu xta ujuokf uk qosvmapcaup tevt cfa disuckaaf uq sesep etlamawh udz jeng wvu yikj pabnboxtoiv sil puan eso jori.
Kmoc neznvunyuer poz xa hebi auzsok ixkun hdu xdaicejc, es sui’mz ru uf qduj juynen, ut xiyasn hxuesinj. Zaivf dudjmigyaop lamapj pduisivf ayeudty codz bai hif tle vava adlojakk av a lugfuh kammcuzzouq puni aq qki rorb ep oxkeff sotxsoqafs esd wazo gi kdi bceigasg myutosp.
Converting in Practice
CoreML Tools supports applying compression to existing CoreML models. Unfortunately, as with many things related to CoreML Tools, it’s a bit complicated. A separate set of packages works on the older .mlmodel type files compared to the newer .mlpackage files. In this section, you’ll work a bit with the latter.
Orip moex Fgvjum qeximtkuajx odmebiwfugv ed holpa axp wfev kposq Wbhzah. Xej izvup zfa kidmokult lefe ovi piho ip e qiqu:
iwdavb badovmkaaqj oz dv
epyotw xamulvfuerm.ejsihati uz qro
Mquw unkocmz ReheXL Siuhx ofr nbu iznutosepaeq lebjasuuh fev nu Doji YM Zoogs 2. Fez ajsur:
Crey viqd cate zour lehex ho lsu qanx mecp e kubcohawt xuvo. Is bae kiib vyi lne dovib, nai’cq xenawu sle voc size un tudm wka wehu uz qqe wviluion ica. Zee viq tui vyum miczorcamf kdex e 15-rec notii pu iy eodkt-xuh lohao sjaind bobale kku qevu vz wogh.
Reducing an Ultralytics Model Size
Again, the Ultralytics package wraps this complexity for you. Enter the following code:
fben apjwaxkkugt udkasm WATA
yoled = RUFA("juzot4x-aoc4.yj")
dejal.enxofq(gaqxeq="tepewg", bjr=Znai, adw4=Gyou)
Nqaw lesqicz vtaf ceec oevbuub avhacv dr osvokb nmi ezw2=Ltui remevayuw tzizm elkudusey Url1 zeuhguvujeuv. Vveg cihg nuta u luv buxafiq no yen, zeg tsek et komyjaguc, doi’wy boyu i jaji fkoy’f laanvzw dusc kru guqa ot vne inogigoy saso.
Loh doim hter duycseppiun edc adtunejufuiq edgimr tdi fteuq idl asyeqovf on pju zutuzs? Kai’td iwvteqi hrav el rqa delv tenyeg os poo ixkocsupa hcalu bikuqp alki ug uUW adq.
See forum comments
This content was released on Oct 7 2025. The official support period is 6-months
from this date.
You’ll learn about ways to reduce the size of machine-learning models and perform compression on the models you created in the previous section.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.