Sparsezoo adalah repositori yang terus-menerus tumbuh dari model yang dibuang (dipangkas dan dipangkas) dengan resep sparsifikasi yang cocok untuk jaringan saraf. Ini menyederhanakan dan mempercepat nilai waktu Anda dalam membangun model pembelajaran mendalam performant dengan kumpulan model dan resep yang dioptimalkan inferensi untuk prototipe. Baca lebih lanjut tentang sparsifikasi.
Tersedia melalui API dan di -host di cloud, Sparsezoo berisi baseline dan model yang dibuang dengan berbagai tingkat kinerja inferensi vs pemulihan kehilangan baseline. Pendekatan yang digerakkan oleh resep yang dibangun di sekitar algoritma sparsifikasi memungkinkan Anda untuk menggunakan model seperti yang diberikan, belajar dari model ke set data pribadi, atau mentransfer resep ke arsitektur Anda.
Repositori GitHub berisi kode API Python untuk menangani koneksi dan otentikasi ke cloud.
AI generatif
Repositori ini diuji pada sistem Python 3.8-3.11, dan Linux/Debian. Disarankan untuk menginstal di lingkungan virtual untuk menjaga sistem Anda tetap teratur.
Instal dengan PIP menggunakan:
pip install sparsezooSparsezoo Python API memungkinkan Anda untuk mencari dan mengunduh model yang dibuang. Contoh kode diberikan di bawah ini. Kami mendorong pengguna untuk memuat model Sparsezoo dengan menyalin rintisan langsung dari halaman model.
Model ini adalah objek mendasar yang berfungsi sebagai antarmuka utama dengan perpustakaan Sparsezoo. Ini mewakili model Sparsezoo, bersama dengan semua direktori dan file.
from sparsezoo import Model
stub = "zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none"
model = Model ( stub )
print ( str ( model ))
>> Model ( stub = zoo : cv / classification / resnet_v1 - 50 / pytorch / sparseml / imagenet / pruned95_quant - none ) from sparsezoo import Model
directory = ".../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0"
model = Model ( directory )
print ( str ( model ))
>> Model ( directory = ... / . cache / sparsezoo / eb977dae - 2454 - 471 b - 9870 - 4 cf38074acf0 ) Kecuali ditentukan sebaliknya, model yang dibuat dari rintisan Sparsezoo disimpan ke direktori cache Sparsezoo lokal. Ini dapat ditimpa dengan meneruskan argumen download_path opsional ke konstruktor:
from sparsezoo import Model
stub = "zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none"
download_directory = "./model_download_directory"
model = Model ( stub , download_path = download_directory ) Setelah model diinisialisasi dari rintisan, dapat diunduh baik dengan memanggil metode download() atau dengan memohon properti path . Kedua jalur itu universal untuk semua file di Sparsezoo. Memanggil properti path akan selalu memicu unduhan file kecuali jika file telah diunduh.
# method 1
model . download ()
# method 2
model_path = model . path Kami memanggil metode available_files untuk memeriksa file mana yang ada dalam model Sparsezoo. Kemudian, kami memilih file dengan memanggil atribut yang sesuai:
model . available_files
>> { 'training' : Directory ( name = training ),
>> 'deployment' : Directory ( name = deployment ),
>> 'sample_inputs' : Directory ( name = sample_inputs . tar . gz ),
>> 'sample_outputs' : { 'framework' : Directory ( name = sample_outputs . tar . gz )},
>> 'sample_labels' : Directory ( name = sample_labels . tar . gz ),
>> 'model_card' : File ( name = model . md ),
>> 'recipes' : Directory ( name = recipe ),
>> 'onnx_model' : File ( name = model . onnx )}Kemudian, kita mungkin melihat lebih dekat konten model Sparsezoo:
model_card = model . model_card
print ( model_card )
>> File ( name = model . md ) model_card_path = model . model_card . path
print ( model_card_path )
>> ... / . cache / sparsezoo / eb977dae - 2454 - 471 b - 9870 - 4 cf38074acf0 / model . md Secara umum, setiap file dalam model Sparsezoo berbagi satu set atribut: name , path , URL , dan parent :
name berfungsi sebagai pengidentifikasi file/direktoripath menunjuk ke lokasi file/direktoriURL Menentukan alamat server file/direktori yang dimaksudparent menunjuk ke lokasi direktori induk file/direktori yang dimaksud Direktori adalah jenis file unik yang berisi file lain. Untuk alasan itu, ia memiliki atribut files tambahan.
print ( model . onnx_model )
>> File ( name = model . onnx )
print ( f"File name: { model . onnx_model . name } n "
f"File path: { model . onnx_model . path } n "
f"File URL: { model . onnx_model . url } n "
f"Parent directory: { model . onnx_model . parent_directory } " )
>> File name : model . onnx
>> File path : ... / . cache / sparsezoo / eb977dae - 2454 - 471 b - 9870 - 4 cf38074acf0 / model . onnx
>> File URL : https : // models . neuralmagic . com / cv - classification / ...
>> Parent directory : ... / . cache / sparsezoo / eb977dae - 2454 - 471 b - 9870 - 4 cf38074acf0 print ( model . recipes )
>> Directory ( name = recipe )
print ( f"File name: { model . recipes . name } n "
f"Contains: { [ file . name for file in model . recipes . files ] } n "
f"File path: { model . recipes . path } n "
f"File URL: { model . recipes . url } n "
f"Parent directory: { model . recipes . parent_directory } " )
>> File name : recipe
>> Contains : [ 'recipe_original.md' , 'recipe_transfer-classification.md' ]
>> File path : / home / user / . cache / sparsezoo / eb977dae - 2454 - 471 b - 9870 - 4 cf38074acf0 / recipe
>> File URL : None
>> Parent directory : / home / user / . cache / sparsezoo / eb977dae - 2454 - 471 b - 9870 - 4 cf38074acf0Model Sparsezoo dapat berisi beberapa pos pemeriksaan. Model mungkin berisi pos pemeriksaan yang telah disimpan sebelum model dikuantisasi - pos pemeriksaan itu akan digunakan untuk pembelajaran transfer. Pos pemeriksaan lain mungkin telah disimpan setelah langkah kuantisasi - yang biasanya digunakan secara langsung untuk inferensi.
Resep juga dapat bervariasi tergantung pada kasus penggunaan. Kami mungkin ingin mengakses resep yang digunakan untuk meluangkan model padat ( recipe_original ) atau yang memungkinkan kami untuk transfer jarang belajar dari model yang sudah dibuang ( recipe_transfer ).
Ada dua cara untuk mengakses file -file tertentu.
available_recipes = model . recipes . available
print ( available_recipes )
>> [ 'original' , 'transfer-classification' ]
transfer_recipe = model . recipes [ "transfer-classification" ]
print ( transfer_recipe )
>> File ( name = recipe_transfer - classification . md )
original_recipe = model . recipes . default # recipe defaults to `original`
original_recipe_path = original_recipe . path # downloads the recipe and returns its path
print ( original_recipe_path )
>> ... / . cache / sparsezoo / eb977dae - 2454 - 471 b - 9870 - 4 cf38074acf0 / recipe / recipe_original . md Secara umum, kami mengharapkan pos pemeriksaan berikut untuk dimasukkan dalam model:
checkpoint_prepruningcheckpoint_postpruningcheckpoint_preqatcheckpoint_postqat Pos Pemeriksaan bahwa model default adalah keadaan preqat (tepat sebelum langkah kuantisasi).
from sparsezoo import Model
stub = "zoo:nlp/question_answering/bert-base/pytorch/huggingface/squad/pruned_quant_3layers-aggressive_84"
model = Model ( stub )
available_checkpoints = model . training . available
print ( available_checkpoints )
>> [ 'preqat' ]
preqat_checkpoint = model . training . default # recipe defaults to `preqat`
preqat_checkpoint_path = preqat_checkpoint . path # downloads the checkpoint and returns its path
print ( preqat_checkpoint_path )
>> ... / . cache / sparsezoo / 0857 c6f2 - 13 c1 - 43 c9 - 8 db8 - 8 f89a548dccd / training
[ print ( file . name ) for file in preqat_checkpoint . files ]
>> vocab . txt
>> special_tokens_map . json
>> pytorch_model . bin
>> config . json
>> training_args . bin
>> tokenizer_config . json
>> trainer_state . json
>> tokenizer . json Anda juga dapat secara langsung meminta jenis resep/pos pemeriksaan tertentu dengan menambahkan argumen kueri URL yang sesuai ke rintisan:
from sparsezoo import Model
stub = "zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none?recipe=transfer"
model = Model ( stub )
# Inspect which files are present.
# Note that the available recipes are restricted
# according to the specified URL query arguments
print ( model . recipes . available )
>> [ 'transfer-classification' ]
transfer_recipe = model . recipes . default # Now the recipes default to the one selected by the stub string arguments
print ( transfer_recipe )
>> File ( name = recipe_transfer - classification . md )Pengguna dapat dengan mudah meminta batch sampel data yang mewakili input dan output model.
sample_data = model . sample_batch ( batch_size = 10 )
print ( sample_data [ 'sample_inputs' ][ 0 ]. shape )
>> ( 10 , 3 , 224 , 224 ) # (batch_size, num_channels, image_dim, image_dim)
print ( sample_data [ 'sample_outputs' ][ 0 ]. shape )
>> ( 10 , 1000 ) # (batch_size, num_classes) Fungsi search_models memungkinkan pengguna untuk dengan cepat memfilter isi repositori Sparsezoo untuk menemukan stub yang menarik:
from sparsezoo import search_models
args = {
"domain" : "cv" ,
"sub_domain" : "segmentation" ,
"architecture" : "yolact" ,
}
models = search_models ( ** args )
[ print ( model ) for model in models ]
>> Model ( stub = zoo : cv / segmentation / yolact - darknet53 / pytorch / dbolya / coco / pruned82_quant - none )
>> Model ( stub = zoo : cv / segmentation / yolact - darknet53 / pytorch / dbolya / coco / pruned90 - none )
>> Model ( stub = zoo : cv / segmentation / yolact - darknet53 / pytorch / dbolya / coco / base - none ) Pengguna dapat menentukan direktori di mana model (sementara selama diunduh) dan kredensial yang diperlukan akan disimpan di mesin kerja Anda. SPARSEZOO_MODELS_PATH adalah jalur di mana model yang diunduh akan disimpan sementara. Default ~/.cache/sparsezoo/ SPARSEZOO_CREDENTIALS_PATH adalah jalur di mana credentials.yaml akan disimpan. Default ~/.cache/sparsezoo/
Selain API Python, titik masuk skrip konsol diinstal dengan paket sparsezoo . Ini memungkinkan interaksi yang mudah langsung dari konsol/terminal Anda.
Unduh Bantuan Perintah
sparsezoo.download -h
Unduh model resnet-50
sparsezoo.download zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/base-none
Unduh model resnet-50 yang dipangkas dan terkuantisasi
sparsezoo.download zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned_quant-moderatePencarian Perintah Bantuan
sparsezoo search -h
Mencari semua model MobileNetV1 klasifikasi di domain visi komputer
sparsezoo search --domain cv --sub-domain classification --architecture mobilenet_v1
Mencari semua model ResNet-50
sparsezoo search --domain cv --sub-domain classification
--architecture resnet_v1 --sub-architecture 50Untuk bacaan yang lebih mendalam, lihat dokumentasi Sparsezoo.
Bangunan resmi di -host di PYPI
Selain itu, informasi lebih lanjut dapat ditemukan melalui rilis GitHub.
Proyek ini dilisensikan di bawah Lisensi Apache versi 2.0.
Kami menghargai kontribusi pada kode, contoh, integrasi, dan dokumentasi serta laporan bug dan permintaan fitur! Pelajari bagaimana di sini.
Untuk bantuan pengguna atau pertanyaan tentang sparsezoo, daftar atau masuk ke komunitas saraf saraf saraf kami Slack . Kami menumbuhkan anggota komunitas oleh anggota dan senang melihat Anda di sana. Bug, permintaan fitur, atau pertanyaan tambahan juga dapat diposting ke antrian masalah GitHub kami.
Anda bisa mendapatkan berita terbaru, webinar dan undangan acara, makalah penelitian, dan informasi ML lainnya dengan berlangganan komunitas sihir saraf.
Untuk pertanyaan yang lebih umum tentang sihir saraf, silakan isi formulir ini.