
Mars는 Numpy, Pandas, Scikit-Learn 및 기타 여러 라이브러리를 확장하는 대규모 데이터 계산을위한 텐서 기반 통합 프레임 워크입니다.
문서, 中文文档
화성은 설치하기 쉽습니다
pip install pymars화성에 코드를 기여하려면 아래 지침을 따라 개발을위한 화성을 설치할 수 있습니다.
git clone https://github.com/mars-project/mars.git
cd mars
pip install -e " .[dev] "화성 설치에 대한 자세한 내용은 화성 문서의 설치 섹션에서 확인할 수 있습니다.
다음을 통해 로컬로 새 런타임 시작 :
> >> import mars
> >> mars . new_session ()또는 이미 초기화 된 화성 클러스터에 연결합니다.
> >> import mars
> >> mars . new_session ( 'http://<web_ip>:<ui_port>' )Mars Tensor는 Numpy와 같은 친숙한 인터페이스를 제공합니다.
| Numpy | 화성 텐서 |
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 시간 : 사용자 11.6 S, SYS : 8.22 S,
총 : 19.9 s
벽 시간 : 22.5 s
| 3.14161908
CPU 시간 : 사용자 966ms, SYS : 544ms,
총 : 1.51 s
벽 시간 : 3.77 s
|
화성은 랩톱에서도 여러 코어를 활용할 수 있으며 분산 설정에서는 더 빠를 수 있습니다.
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 시간 : 사용자 10.9 초, SYS : 2.69 S,
총 : 13.6 s
벽 시간 : 11 s
| CPU 시간 : 사용자 1.21 S, SYS : 212ms,
총 : 1.42 s
벽 시간 : 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를 사용하면 사용자가 기능을 병렬로 실행할 수 있습니다.
| 바닐라 기능 호출 | 화성 원격 |
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 시간 : 사용자 32.2 초, SYS : 4.86 S,
총 : 37.1 s
벽 시간 : 12.4 s
| 3.1416312
CPU 시간 : 사용자 616ms, SYS : 307ms,
총 : 923ms
벽 시간 : 3.99 s
|
자세한 내용은 화성 Dask를 참조하십시오.
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
>> > ...열성적인 모드가 켜져 있으면 텐서, 데이터 프레임 등이 생성되면 기본 세션으로 즉시 실행됩니다.
> >> 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 Mars는 또한 Ray와의 깊은 통합을 가지고 있으며 Ray에서 효율적으로 실행될 수 있으며 핵심 Ray 위에 구축 된 기계 학습 및 분산 시스템의 대규모 생태계와 상호 작용할 수 있습니다.
Ray Runtime에서 로컬로 새로운 화성 시작 : :
import mars
mars . new_session ( backend = 'ray' )
# Perform computationRAY 데이터 세트와 상호 작용 :
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 ())자세한 내용은 Ray의 화성을 참조하십시오.
화성은 단일 기계로 확장되어 수천 개의 기계로 클러스터로 확장 할 수 있습니다. 더 많은 데이터를 처리하거나 더 나은 성능을 얻기 위해 단일 시스템에서 클러스터로 마이그레이션하는 것은 상당히 간단합니다.
화성은 클러스터의 다른 기계에서 화성 분산 런타임의 다른 구성 요소를 시작하여 클러스터로 쉽게 확장 할 수 있습니다.
노드는 웹 서비스를 통합 한 감독자로 선택할 수 있으며 다른 노드를 작업자로 남겨 둡니다. 감독자는 다음 명령으로 시작할 수 있습니다.
mars-supervisor -h < host_name > -p < supervisor_port > -w < web_port >작업자는 다음 명령으로 시작할 수 있습니다.
mars-worker -h < host_name > -p < worker_port > -s < supervisor_endpoint >모든 화성 프로세스가 시작된 후 사용자는 실행할 수 있습니다
> >> sess = new_session ( 'http://<web_ip>:<ui_port>' )
> >> # perform computation자세한 내용은 Kubernetes에서 실행을 참조하십시오.
자세한 내용은 원사 실행을 참조하십시오.
귀하의 기여에 미리 감사드립니다!