
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
Mars是一个基于张量的统一框架,用于大规模数据计算,可扩展Numpy、Pandas和Scikit-learn等常用数据科学库。它能够利用单机多核心或分布式集群资源,在保持接口熟悉性的同时显著提升计算效率,适用于处理大规模数据集和机器学习任务。
提供与Numpy类似的接口,支持大规模张量运算,可利用多核心或分布式资源加速计算。
| Numpy | Mars Tensor |
|---|---|
| ```python | |
| 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) | |
| ``` | ```python |
| 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.14151712 CPU times: user 12.5 s, sys: 7.16 s, total: 19.7 s Wall time: 21.8 s ```|``` 3.14161908 CPU times: user 17.5 s, sys: 3.56 s, total: 21.1 s Wall time: 5.59 s ```| ### Mars DataFrame 提供与Pandas类似的接口,支持大规模DataFrame操作,优化并行计算性能。 | **Pandas** | **Mars DataFrame** | |------------|--------------------| |```python import numpy as np import pandas as pd df = pd.DataFrame( np.random.rand(100000000, 4), columns=list('abcd')) print(df.sum()) ```|```python 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: user 10.9 s, sys: 2.69 s, total: 13.6 s Wall time: 11 s ```|``` CPU times: user 16.5 s, sys: 3.52 s, total: 20 s Wall time: 3.6 s ```| ### Mars Learn 提供与Scikit-learn类似的接口,支持大规模机器学习算法,兼容常用模型和数据处理流程。 ```python 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_)
支持并行执行函数,通过mr.spawn实现任务分发和并行计算,提升多任务处理效率。
| 普通函数调用 | Mars Remote |
|---|---|
| ```python | |
| 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)
|python
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: user 32.2 s, sys: 4.86 s, total: 37.1 s Wall time: 12.4 s ```|``` 3.1416312 CPU times: user 16.9 s, sys: 5.46 s, total: 22.3 s Wall time: 4.83 s ```| ### Eager Mode 支持即时执行模式,便于开发和调试。可通过全局配置或上下文管理器启用。 ```python # 全局启用 from mars.config import options options.eager_mode = True # 上下文启用 from mars.config import option_context with option_context() as options: options.eager_mode = True # 在此上下文中eager mode生效
启用后,张量和DataFrame会在创建时自动执行:
pythonimport 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)) print(t) # 直接输出结果,无需调用execute() # array([[0, 1, 2], # [3, 4, 5]]) df = md.DataFrame(t) print(df.sum()) # 0 3 # 1 5 # 2 7 # dtype: int64
bashpip install pymars
bashpip install 'pymars[distributed]'
bashgit clone https://github.com/mars-project/mars.git cd mars pip install -e ".[dev]"
线程模式(默认)
在单机上使用线程调度执行任务:
pythonimport mars.tensor as mt a = mt.ones((10, 10)) a.execute() # 默认使用线程调度 # 显式创建会话 from mars.session import new_session session = new_session() (a * 2).execute(session=session) # 上下文管理器方式 with new_session() as session2: (a / 3).execute(session=session2)
本地集群模式
在单机上启动分布式组件的本地集群(需安装分布式版本):
pythonfrom mars.deploy.local import new_cluster # 创建本地集群并设置为默认会话 cluster = new_cluster() (a + 1).execute() # 在本地集群上运行 # 显式指定集群端点创建会话 session = new_session(cluster.endpoint) (a * 3).execute(session=session)
分布式集群模式
在多节点集群上部署:
bashmars-scheduler -a <scheduler_ip> -p <scheduler_port>
bashmars-web -a <web_ip> -s <scheduler_endpoint> --ui-port <ui_port_exposed_to_user>
bashmars-worker -a <worker_ip> -p <worker_port> -s <scheduler_endpoint>
pythonfrom mars.session import new_session sess = new_session('http://<web_ip>:<ui_port>') a = mt.ones((2000, 2000), chunk_size=200) b = mt.inner(a, a) b.execute(session=sess)
感谢您的贡献!
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。




来自真实用户的反馈,见证轩辕镜像的优质服务