Sparsezoo เป็นพื้นที่เก็บข้อมูลที่เติบโตอย่างต่อเนื่องของแบบจำลอง sparsified (ตัดแต่งและตัดแต่งกิ่ง) กับสูตรการจับคู่ sparsification สำหรับเครือข่ายประสาท มันง่ายขึ้นและเร่งความเร็วเวลาของคุณในการสร้างแบบจำลองการเรียนรู้เชิงลึกที่นักแสดงด้วยคอลเลกชันของแบบจำลองการอนุมานที่เหมาะสมและสูตรอาหารเพื่อต้นแบบจาก อ่านเพิ่มเติมเกี่ยวกับ sparsification
มีให้ผ่าน API และโฮสต์ในคลาวด์ Finsezoo มีทั้งพื้นฐานและรุ่นที่กระจายไปตามระดับการอนุมานที่แตกต่างกันกับการกู้คืนการสูญเสียพื้นฐาน วิธีการที่ขับเคลื่อนด้วยสูตรที่สร้างขึ้นรอบอัลกอริทึม sparsification ช่วยให้คุณใช้โมเดลตามที่กำหนดการถ่ายโอน-เรียนรู้จากโมเดลไปยังชุดข้อมูลส่วนตัวหรือถ่ายโอนสูตรอาหารไปยังสถาปัตยกรรมของคุณ
ที่เก็บ GitHub มีรหัส Python API เพื่อจัดการการเชื่อมต่อและการรับรองความถูกต้องกับคลาวด์
AI Generative
ที่เก็บนี้ได้รับการทดสอบใน Python 3.8-3.11 และระบบ Linux/Debian ขอแนะนำให้ติดตั้งในสภาพแวดล้อมเสมือนจริงเพื่อให้ระบบของคุณเป็นระเบียบ
ติดตั้งด้วย PIP โดยใช้:
pip install sparsezooSparsezoo Python API ช่วยให้คุณสามารถค้นหาและดาวน์โหลดรุ่น sparsified ตัวอย่างรหัสได้รับด้านล่าง เราขอแนะนำให้ผู้ใช้โหลดโมเดล Sparsezoo โดยการคัดลอกต้นขั้วโดยตรงจากหน้ารุ่น
Model เป็นวัตถุพื้นฐานที่ทำหน้าที่เป็นอินเทอร์เฟซหลักกับไลบรารี Sparsezoo มันแสดงถึงโมเดล Sparsezoo พร้อมกับไดเรกทอรีและไฟล์ทั้งหมด
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 ) เว้นแต่จะระบุไว้เป็นอย่างอื่นโมเดลที่สร้างขึ้นจากต้นขั้ว sparsezoo จะถูกบันทึกลงในไดเรกทอรีแคช Sparsezoo ท้องถิ่น สิ่งนี้สามารถแทนที่ได้โดยผ่านอาร์กิวเมนต์ download_path เสริมไปยังตัวสร้าง:
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 ) เมื่อโมเดลเริ่มต้นจากต้นขั้วอาจดาวน์โหลดได้โดยเรียกวิธี download() หรือโดยการเรียกใช้คุณสมบัติ path เส้นทางทั้งสองเป็นสากลสำหรับไฟล์ทั้งหมดใน Sparsezoo การเรียกใช้คุณสมบัติ path จะทริกเกอร์การดาวน์โหลดไฟล์เว้นแต่ว่าไฟล์ได้ถูกดาวน์โหลดไปแล้ว
# method 1
model . download ()
# method 2
model_path = model . path เราเรียกวิธีการ available_files เพื่อตรวจสอบไฟล์ที่มีอยู่ในโมเดล Sparsezoo จากนั้นเราเลือกไฟล์โดยเรียกแอตทริบิวต์ที่เหมาะสม:
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 )}จากนั้นเราอาจดูเนื้อหาของโมเดล 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 โดยทั่วไปไฟล์ทุกไฟล์ในโมเดล Sparsezoo จะแชร์ชุดของแอตทริบิวต์: name , path , URL และ parent :
name ทำหน้าที่เป็นตัวระบุไฟล์/ไดเรกทอรีpath ธ ชี้ไปที่ตำแหน่งของไฟล์/ไดเรกทอรีURL ระบุที่อยู่เซิร์ฟเวอร์ของไฟล์/ไดเรกทอรีที่เป็นปัญหาparent ชี้ไปที่ตำแหน่งของไดเรกทอรีหลักของไฟล์/ไดเรกทอรีที่เป็นปัญหา ไดเรกทอรีเป็นประเภทที่ไม่ซ้ำกันของไฟล์ที่มีไฟล์อื่น ๆ ด้วยเหตุนี้จึงมีแอตทริบิวต์ files เพิ่มเติม
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 cf38074acf0โมเดล Sparsezoo อาจมีจุดตรวจหลายแห่ง แบบจำลองอาจมีจุดตรวจสอบที่ได้รับการบันทึกก่อนที่โมเดลจะถูกวัดปริมาณ - จุดตรวจนั้นจะถูกใช้สำหรับการถ่ายโอนการเรียนรู้ จุดตรวจอื่นอาจได้รับการบันทึกหลังจากขั้นตอนการหาปริมาณ - ซึ่งมักจะใช้โดยตรงสำหรับการอนุมาน
สูตรอาจแตกต่างกันไปขึ้นอยู่กับกรณีการใช้งาน เราอาจต้องการเข้าถึงสูตรที่ใช้ในการทำให้โมเดลหนาแน่น ( recipe_original ) หรือสูตรที่ช่วยให้เราสามารถถ่ายโอนได้เรียนรู้จากโมเดล sparsified แล้ว ( recipe_transfer )
มีสองวิธีในการเข้าถึงไฟล์เฉพาะเหล่านั้น
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 โดยทั่วไปเราคาดหวังว่าจุดตรวจสอบต่อไปนี้จะรวมอยู่ในโมเดล:
checkpoint_prepruningcheckpoint_postpruningcheckpoint_preqatcheckpoint_postqat จุดตรวจสอบที่รุ่นเริ่มต้นคือสถานะ preqat (ก่อนขั้นตอนการหาปริมาณ)
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 นอกจากนี้คุณยังสามารถขอประเภทสูตร/จุดตรวจสอบเฉพาะได้โดยตรงโดยเพิ่มอาร์กิวเมนต์ URL แบบสอบถามที่เหมาะสมกับต้นขั้ว:
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 )ผู้ใช้อาจขอชุดข้อมูลตัวอย่างที่แสดงถึงอินพุตและเอาต์พุตของโมเดลได้อย่างง่ายดาย
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) ฟังก์ชั่น search_models ช่วยให้ผู้ใช้สามารถกรองเนื้อหาของที่เก็บ Sparsezoo ได้อย่างรวดเร็วเพื่อค้นหาต้นขั้วที่น่าสนใจ:
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 ) ผู้ใช้สามารถระบุไดเรกทอรีที่รุ่น (ชั่วคราวระหว่างการดาวน์โหลด) และข้อมูลรับรองที่จำเป็นจะถูกบันทึกไว้ในเครื่องทำงานของคุณ SPARSEZOO_MODELS_PATH เป็นเส้นทางที่รุ่นที่ดาวน์โหลดจะถูกบันทึกชั่วคราว ค่าเริ่มต้น ~/.cache/sparsezoo/ SPARSEZOO_CREDENTIALS_PATH เป็นเส้นทางที่มีการบันทึก credentials.yaml yaMl ค่าเริ่มต้น ~/.cache/sparsezoo/
นอกเหนือจาก Python API แล้วยังมีการติดตั้งจุดเข้าร่วมคอนโซลสคริปต์ด้วยแพ็คเกจ sparsezoo สิ่งนี้ช่วยให้การโต้ตอบได้ง่ายจากคอนโซล/เทอร์มินัลของคุณ
ดาวน์โหลดคำสั่ง HELP
sparsezoo.download -h
ดาวน์โหลดรุ่น resnet-50
sparsezoo.download zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/base-none
ดาวน์โหลดรุ่น resnet-50 แบบตัดแต่งและเชิงปริมาณ
sparsezoo.download zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned_quant-moderateความช่วยเหลือคำสั่งค้นหา
sparsezoo search -h
ค้นหาโมเดล Mobilenetv1 การจำแนกประเภททั้งหมดในโดเมน Vision Computer
sparsezoo search --domain cv --sub-domain classification --architecture mobilenet_v1
ค้นหารุ่น Resnet-50 ทั้งหมด
sparsezoo search --domain cv --sub-domain classification
--architecture resnet_v1 --sub-architecture 50สำหรับการอ่านเชิงลึกเพิ่มเติมลองดูเอกสาร Finsezoo
งานสร้างอย่างเป็นทางการเป็นเจ้าภาพใน PYPI
นอกจากนี้ข้อมูลเพิ่มเติมสามารถพบได้ผ่านการเผยแพร่ GitHub
โครงการได้รับใบอนุญาตภายใต้ Apache License Version 2.0
เราขอขอบคุณที่มีส่วนร่วมในรหัสตัวอย่างการรวมและเอกสารรวมถึงรายงานข้อผิดพลาดและคำขอคุณสมบัติ! เรียนรู้วิธีการที่นี่
สำหรับความช่วยเหลือของผู้ใช้หรือคำถามเกี่ยวกับ Sparsezoo, ลงทะเบียนหรือเข้าสู่ระบบของ ชุมชนเวทมนตร์ประสาท ของเรา เรากำลังเติบโตสมาชิกชุมชนโดยสมาชิกและมีความสุขที่ได้พบคุณที่นั่น ข้อบกพร่องคำขอคุณสมบัติหรือคำถามเพิ่มเติมสามารถโพสต์ไปยังคิวปัญหา GitHub ของเราได้
คุณสามารถรับข่าวสารล่าสุดการสัมมนาผ่านเว็บและการเชิญงานงานวิจัยและเกร็ดความรู้อื่น ๆ ของ ML โดยการสมัครรับชุมชนเวทมนตร์ประสาท
สำหรับคำถามทั่วไปเพิ่มเติมเกี่ยวกับเวทมนตร์ของระบบประสาทโปรดกรอกแบบฟอร์มนี้