
Mars เป็นเฟรมเวิร์กแบบครบวงจรที่ใช้เทนเซอร์สำหรับการคำนวณข้อมูลขนาดใหญ่ซึ่งปรับขนาด Numpy, Pandas, Scikit-Learn และห้องสมุดอื่น ๆ อีกมากมาย
เอกสาร中文文档
ดาวอังคารติดตั้งง่ายโดย
pip install pymarsเมื่อคุณต้องการมีส่วนร่วมในรหัสไปยัง Mars คุณสามารถทำตามคำแนะนำด้านล่างเพื่อติดตั้ง Mars เพื่อการพัฒนา:
git clone https://github.com/mars-project/mars.git
cd mars
pip install -e " .[dev] "รายละเอียดเพิ่มเติมเกี่ยวกับการติดตั้ง MARS สามารถดูได้ที่ส่วนการติดตั้งในเอกสาร Mars
เริ่มต้นรันไทม์ใหม่ในพื้นที่ผ่าน:
> >> import mars
> >> mars . new_session ()หรือเชื่อมต่อกับคลัสเตอร์ดาวอังคารซึ่งเริ่มต้นแล้ว
> >> import mars
> >> mars . new_session ( 'http://<web_ip>:<ui_port>' )Mars Tensor ให้อินเทอร์เฟซที่คุ้นเคยเช่น NumPy
| นม | MARS TENSOR |
import numpy as np
N = 200_000_000
a = np . random . uniform ( - 1 , 1 , size = ( N , 2 ))
print (( np . linalg . norm ( a , axis = 1 ) < 1 )
. sum () * 4 / N ) | import mars . tensor as mt
N = 200_000_000
a = mt . random . uniform ( - 1 , 1 , size = ( N , 2 ))
print ((( mt . linalg . norm ( a , axis = 1 ) < 1 )
. sum () * 4 / N ). execute ()) |
3.14174502
CPU Times: ผู้ใช้ 11.6 S, SYS: 8.22 S,
รวม: 19.9 วินาที
Wall Time: 22.5 S
| 3.14161908
CPU Times: ผู้ใช้ 966 MS, SYS: 544 ms,
ทั้งหมด: 1.51 s
Wall Time: 3.77 S
|
ดาวอังคารสามารถใช้ประโยชน์จากหลายคอร์แม้ในแล็ปท็อปและอาจเร็วกว่าสำหรับการตั้งค่าแบบกระจาย
Mars DataFrame ให้อินเทอร์เฟซที่คุ้นเคยเช่นแพนด้า
| แพนด้า | mars dataframe |
import numpy as np
import pandas as pd
df = pd . DataFrame (
np . random . rand ( 100000000 , 4 ),
columns = list ( 'abcd' ))
print ( df . sum ()) | import mars . tensor as mt
import mars . dataframe as md
df = md . DataFrame (
mt . random . rand ( 100000000 , 4 ),
columns = list ( 'abcd' ))
print ( df . sum (). execute ()) |
CPU Times: ผู้ใช้ 10.9 S, SYS: 2.69 s,
รวม: 13.6 s
Wall Time: 11 S
| CPU Times: ผู้ใช้ 1.21 S, SYS: 212 ms,
ทั้งหมด: 1.42 s
Wall Time: 2.75 S
|
Mars Learn ให้อินเทอร์เฟซที่คุ้นเคยเช่น Scikit-Learn
| Scikit-learn | ดาวอังคารเรียนรู้ |
from sklearn . datasets import make_blobs
from sklearn . decomposition import PCA
X , y = make_blobs (
n_samples = 100000000 , n_features = 3 ,
centers = [[ 3 , 3 , 3 ], [ 0 , 0 , 0 ],
[ 1 , 1 , 1 ], [ 2 , 2 , 2 ]],
cluster_std = [ 0.2 , 0.1 , 0.2 , 0.2 ],
random_state = 9 )
pca = PCA ( n_components = 3 )
pca . fit ( X )
print ( pca . explained_variance_ratio_ )
print ( pca . explained_variance_ ) | from mars . learn . datasets import make_blobs
from mars . learn . decomposition import PCA
X , y = make_blobs (
n_samples = 100000000 , n_features = 3 ,
centers = [[ 3 , 3 , 3 ], [ 0 , 0 , 0 ],
[ 1 , 1 , 1 ], [ 2 , 2 , 2 ]],
cluster_std = [ 0.2 , 0.1 , 0.2 , 0.2 ],
random_state = 9 )
pca = PCA ( n_components = 3 )
pca . fit ( X )
print ( pca . explained_variance_ratio_ )
print ( pca . explained_variance_ ) |
Mars Learn ยังรวมเข้ากับห้องสมุดหลายแห่ง:
Mars Remote ช่วยให้ผู้ใช้สามารถเรียกใช้ฟังก์ชั่นแบบขนาน
| การเรียกใช้ฟังก์ชันวานิลลา | Mars Remote |
import numpy as np
def calc_chunk ( n , i ):
rs = np . random . RandomState ( i )
a = rs . uniform ( - 1 , 1 , size = ( n , 2 ))
d = np . linalg . norm ( a , axis = 1 )
return ( d < 1 ). sum ()
def calc_pi ( fs , N ):
return sum ( fs ) * 4 / N
N = 200_000_000
n = 10_000_000
fs = [ calc_chunk ( n , i )
for i in range ( N // n )]
pi = calc_pi ( fs , N )
print ( pi ) | import numpy as np
import mars . remote as mr
def calc_chunk ( n , i ):
rs = np . random . RandomState ( i )
a = rs . uniform ( - 1 , 1 , size = ( n , 2 ))
d = np . linalg . norm ( a , axis = 1 )
return ( d < 1 ). sum ()
def calc_pi ( fs , N ):
return sum ( fs ) * 4 / N
N = 200_000_000
n = 10_000_000
fs = [ mr . spawn ( calc_chunk , args = ( n , i ))
for i in range ( N // n )]
pi = mr . spawn ( calc_pi , args = ( fs , N ))
print ( pi . execute (). fetch ()) |
3.1416312
CPU Times: ผู้ใช้ 32.2 S, SYS: 4.86 S,
รวม: 37.1 s
Wall Time: 12.4 S
| 3.1416312
CPU Times: ผู้ใช้ 616 ms, Sys: 307 ms,
รวม: 923 ms
Wall Time: 3.99 S
|
อ้างถึง Dask on Mars สำหรับข้อมูลเพิ่มเติม
ดาวอังคารรองรับโหมดกระตือรือร้นซึ่งทำให้เป็นมิตรสำหรับการพัฒนาและดีบักดีต่อการดีบัก
ผู้ใช้สามารถเปิดใช้งานโหมดกระตือรือร้นตามตัวเลือกตั้งค่าตัวเลือกที่จุดเริ่มต้นของโปรแกรมหรือเซสชันคอนโซล
> >> from mars . config import options
> >> options . eager_mode = Trueหรือใช้บริบท
> >> from mars . config import option_context
> >> with option_context () as options :
> >> options . eager_mode = True
> >> # the eager mode is on only for the with statement
>> > ...หากเปิดโหมด Eager, Tensor, DataFrame ฯลฯ จะถูกเรียกใช้งานทันทีโดยเซสชันเริ่มต้นเมื่อสร้างขึ้น
> >> import mars . tensor as mt
> >> import mars . dataframe as md
> >> from mars . config import options
> >> options . eager_mode = True
> >> t = mt . arange ( 6 ). reshape (( 2 , 3 ))
> >> t
array ([[ 0 , 1 , 2 ],
[ 3 , 4 , 5 ]])
> >> df = md . DataFrame ( t )
> >> df . sum ()
0 3
1 5
2 7
dtype : int64 ดาวอังคารยังมีการบูรณาการอย่างลึกซึ้งกับเรย์และสามารถทำงานบนเรย์ได้อย่างมีประสิทธิภาพและโต้ตอบกับระบบนิเวศขนาดใหญ่ของการเรียนรู้ของเครื่องและระบบกระจายที่สร้างขึ้นบนพื้นฐานของเรย์แกน
เริ่มต้นดาวอังคารใหม่บนรันไทม์เรย์ในพื้นที่ผ่าน:
import mars
mars . new_session ( backend = 'ray' )
# Perform computationโต้ตอบกับชุดข้อมูลเรย์:
import mars . tensor as mt
import mars . dataframe as md
df = md . DataFrame (
mt . random . rand ( 1000_0000 , 4 ),
columns = list ( 'abcd' ))
# Convert mars dataframe to ray dataset
ds = md . to_ray_dataset ( df )
print ( ds . schema (), ds . count ())
ds . filter ( lambda row : row [ "a" ] > 0.5 ). show ( 5 )
# Convert ray dataset to mars dataframe
df2 = md . read_ray_dataset ( ds )
print ( df2 . head ( 5 ). execute ())อ้างถึงดาวอังคารบนเรย์สำหรับข้อมูลเพิ่มเติม
ดาวอังคารสามารถปรับขนาดในเครื่องเดียวและปรับขนาดให้เป็นคลัสเตอร์ที่มีเครื่องจักรนับพัน มันค่อนข้างง่ายที่จะโยกย้ายจากเครื่องเดียวไปยังคลัสเตอร์เพื่อประมวลผลข้อมูลมากขึ้นหรือเพิ่มประสิทธิภาพที่ดีขึ้น
ดาวอังคารนั้นง่ายต่อการปรับขนาดให้เป็นคลัสเตอร์โดยการเริ่มต้นส่วนประกอบที่แตกต่างกันของรันไทม์ที่กระจาย Mars บนเครื่องจักรที่แตกต่างกันในคลัสเตอร์
โหนดสามารถเลือกเป็นหัวหน้างานที่รวมบริการเว็บออกจากโหนดอื่น ๆ เป็นคนงาน หัวหน้างานสามารถเริ่มต้นด้วยคำสั่งต่อไปนี้:
mars-supervisor -h < host_name > -p < supervisor_port > -w < web_port >คนงานสามารถเริ่มต้นด้วยคำสั่งต่อไปนี้:
mars-worker -h < host_name > -p < worker_port > -s < supervisor_endpoint >หลังจากเริ่มกระบวนการ Mars ทั้งหมดผู้ใช้สามารถเรียกใช้งานได้
> >> sess = new_session ( 'http://<web_ip>:<ui_port>' )
> >> # perform computationอ้างถึงการทำงานบน Kubernetes สำหรับข้อมูลเพิ่มเติม
อ้างถึงการทำงานบนเส้นด้ายสำหรับข้อมูลเพิ่มเติม
ขอบคุณล่วงหน้าสำหรับการมีส่วนร่วมของคุณ!