OneLake 是 Fabric 的開放式湖儲存層,具備 Azure 儲存體 相容的存取權限。 它透過 onelake.dfs.fabric.microsoft.com 公開 Fabric 資料,供 ADLS Gen2/DFS 存取,並透過 onelake.blob.fabric.microsoft.com 供 Blob API 存取。 本文說明 Azure Machine Learning 如何透過 AML 資料儲存、批次端點輸入與輸出,以及直接abfss://從筆記本或腳本存取這些表面。
Azure Machine Learning 提供與 OneLake 的三個主要整合點:
-
Datastores - 將 Fabric Lakehouse
Files位置註冊為 Azure Machine Learning 資料庫,並從工作與資料資產中引用該位置。 Azure Machine Learning 也支援直接連結到 Fabric Lakehouse 資料表,但該模式需複製至 ADLS Gen2,且本文件未涵蓋。 - 批次端點 ——呼叫批次部署,輸入與輸出都存放於 OneLake(現今透過註冊資料儲存或捷徑支援的 Blob/ADLS 資料儲存)。
- OneLake API / 直接 ABFSS 存取——可直接從運行於 Azure Machine Learning 執行環境的筆記本和腳本中讀寫 OneLake。
| Azure Machine Learning 中的整合點 | OneLake 介面 | Azure Machine Learning 介面 | 資料會被複製到 ADLS Gen2 嗎? | Azure Machine Learning 主要使用的 URI |
|---|---|---|---|---|
| OneLake 資料庫 | Lakehouse /Files 區段。 |
CLI / SDK(YAML) | No | azureml://datastores/<name>/paths/<path> |
| OneLake Lakehouse 資料表(已連結 UI) | Lakehouse /Tables 區段。 |
Azure Machine Learning 工作室 (UI) | 是的——透過 Fabric 管線複製到 ADLS Gen2,然後註冊 | azureml://datastores/<adls_ds>/paths/<path> |
| 批次端點輸入/輸出 | Lakehouse /Files(透過 ADLS 捷徑)。 |
CLI / SDK / REST | Optional |
azureml://datastores/<name>/paths/<path> 或 abfss://... |
| 直接存取 OneLake API / ABFSS |
/Files 與 /Tables |
Azure Machine Learning 計算上的筆記本 / 指令碼 | No | abfss://<workspace>@onelake.dfs.fabric.microsoft.com/<lakehouse>.Lakehouse/Files/... |
Note
azureml://是 Azure Machine Learning 專屬的 URI 方案,而非儲存協定。 Azure Machine Learning 控制平面和資料執行時會利用它來解析底層儲存位置(Blob、ADLS Gen2、OneLake 等),方法是利用指定的資料庫中註冊的連線元資料和憑證。
OneLake as an Azure Machine Learning Datastore
資料存放區是 Azure Machine Learning 工作區範圍內,對外部儲存位置(OneLake、Azure Blob、ADLS Gen2、Azure 檔案儲存體)的抽象表示。 它儲存現有儲存資源的連線元資料、端點、容器/檔案系統/項目,以及憑證或身份設定,而不會配置或複製資料本身。 Azure Machine Learning 中的各種經驗可透過穩定的 URIazureml://datastores/<name>/paths/<path>() 來參考資料儲存庫。
Note
Azure Machine Learning 工作室 目前在 UI 中沒有將 OneLake 列為資料儲存類型,但 CLI 和 SDK 支援透過 YAML 定義建立和管理 OneLake 資料儲存。
需要從 Microsoft Fabric 取得的連線中繼資料
從 Fabric 中 Lakehouse 項目的屬性頁面擷取:
-
端點 - OneLake 可以使用
onelake.dfs.fabric.microsoft.com或onelake.blob.fabric.microsoft.com視你想使用的協定而定。 - Workspace GUID
- 項目指南( 湖屋指南)
在 Azure Machine Learning 中建立資料存放區
onelake-datastore.yml:
$schema: https://azuremlschemas.azureedge.net/latest/oneLakeDatastore.schema.json
name: <name_of_datastore>
type: onelake
description: Datastore pointing to a Microsoft Fabric lakehouse.
onelake_workspace_name: <workspace_guid>
endpoint: onelake.dfs.fabric.microsoft.com
artifact:
type: lakehouse
name: <item_guid>/Files # Include /Files in the name to point at the lakehouse Files layer; omit it to point at the root of the item.
使用 Azure CLI,在目標的 Azure Machine Learning 工作空間中建立資料儲存。 將 <name_of_AML_workspace> 和 <name_of_datastore> 佔位符替換為適當的值。
az ml datastore create --file ./onelake-datastore.yml \
--resource-group rg-amlonelake \
--workspace-name <name_of_AML_workspace>
在 Azure Machine Learning jobs 中使用數據存儲
一旦 Azure Machine Learning 資料儲存庫註冊完成,其 azureml:// URI 便可透過各種體驗使用。 此範例示範如何在 Azure Machine Learning 工作中引用 OneLake 資料儲存。 以下 URI 可作為作業 Input/Output、用於資料資產定義中,以及用於任何 Azure Machine Learning 接受資料存放區路徑的位置,但批次端點除外,因為其目前不支援將 OneLake 作為輸入或輸出的資料存放區類型。
以下工作範例是在同一 OneLake 資料儲存庫中,將檔案從一個位置複製到另一個地點。 你可以在同一工作中混合使用多種支援的儲存目標(Blob、ADLS Gen2、OneLake)作為輸入和輸出。
type: command
command: cp ${{inputs.input_data}} ${{outputs.output_data}}
compute: azureml:<replace_with_aml_compute_target>
environment: azureml://registries/azureml/environments/sklearn-1.1/versions/4
inputs:
input_data:
mode: ro_mount
path: azureml://datastores/<name_of_datastore>/paths/<folder-path>/<file-name> # Do not include /Files in the <file-name> portion of the path. Reason being that the datastore is already pointed at the /Files layer of the lakehouse via the artifact name in the datastore definition.
type: uri_file
outputs:
output_data:
mode: rw_mount
path: azureml://datastores/<name_of_datastore>/paths/<folder-path>/<file-name> # Do not include /Files in the <file-name> portion of the path. Reason being that the datastore is already pointed at the /Files layer of the lakehouse via the artifact name in the datastore definition.
type: uri_file
# optional: if you want to create a data asset from the output,
# then uncomment `name` (`name` can be set without setting `version`, and in this way, we will set `version` automatically for you)
# name: <name_of_data_asset> # use `name` and `version` to create a data asset from the output
# version: <version_of_data_asset>
可直接參照 OneLake 資料存放區的 Azure Machine Learning 體驗
| # | Azure Machine Learning 介面 | 方向 | OneLake 位址 | Source |
|---|---|---|---|---|
| 1 |
Azure Machine Learning 作業 - Input / Output(CLI v2、SDK v2 command、pipeline、sweep) |
右 / 西 | azureml://datastores/<onelake_ds>/paths/... |
在作業中存取資料 |
| 2 |
資料資產(uri_file、uri_folder)已註冊至 OneLake 資料存放區路徑 |
R(資產為唯讀參考) |
azureml://datastores/<onelake_ds>/paths/... 並附有版本控制 |
建立資料資產 |
| 3 |
透過 azureml-fsspec 在 Azure Machine Learning 計算上於筆記本/指令碼中使用 Azure Machine Learning 資料執行階段 |
右 / 西 |
azureml://datastores/<onelake_ds>/paths/... 以 fsspec.open(...) 或 AzureMachineLearningFileSystem 開啟 |
互動開發期間可存取 OneLake 的資料 |
帶有批次端點的 OneLake
Azure Machine Learning 讓你能使用 Fabric 存取模型部署批次端點,進行長期執行的非同步推論,並結合機器學習模型與管線。
在此架構目標是同時保留輸入特徵資料與輸出預測的實體副本,並能同時被 Fabric 與 Azure Machine Learning 兩個平台存取。 ADLS 中的檔案有兩個有效位址:一個是 Azure Machine Learning 批次端點可接受作為輸入/輸出的 azureml://datastores/... URI,另一個是湖倉路徑(透過 ADLS 捷徑啟用),可供 Fabric 筆記本、管線和 SQL 分析端點查詢。 這種模式沒有複製、沒有排程同步,也沒有第二真實來源。 湖屋視圖和 Azure Machine Learning 視圖是同一儲存帳號的投影。
批次端點位於兩個 OneLake 可見的資料夾之間:
-
輸入 - 由 Fabric 資料工程團隊精心策劃
/Files的位置(原始著陸、評分請求、每日分割)。 Azure Machine Learning 會透過指向與捷徑相同儲存體的 ADLS Gen2 資料存放區來讀取它。 -
輸出 - 由批次作業寫入相同 ADLS Gen2 帳戶中預測結果的
/Files位置,該位置會透過捷徑顯示在 Lakehouse 中,並可立即供 Fabric 筆記本、資料流或 Delta 資料表載入步驟使用。
更廣泛來說,這種模式非常適合已經有資料進入 ADLS Gen2 的情境。 例如,現有的資料湖會供應分析或機器學習工作負載。 與其將該資料遷移或複製到 OneLake,不如使用 OneLake 捷徑,將現有的 ADLS 位置呈現在 Fabric Lakehouse 中,同時同一個帳戶仍會註冊為資料存放區。
從 Azure Machine Learning 筆記本與指令碼存取 OneLake SDK 或 API
當程式碼在 Azure Machine Learning 運算(計算實例、運算叢集或無伺服器運算)上執行時,它可以直接透過abfss://路徑或 OneLake 資料儲存路徑讀寫 OneLake。 OneLake SDK 與 API 提供彈性的整合介面,可用於以筆記本為基礎的探索、自訂訓練指令碼,以及需要透過 Azure Machine Learning 運算來存取 /Files 和 /Tables 的元件。
OneLake 使用 abfss:// URI 來管理 OneLake 上的檔案,並可作為基於身份或服務主體認證的有效工作輸入路徑:
abfss://<workspace_guid>@<endpoint>/<item_guid>/Files/<path>
效能與可擴展性——在 Azure Machine Learning 中選擇合適的閱讀器
fsspec(以及它所包裝的 OneLake adlfs 後端)是一個 Python 層級的檔案系統抽象化。 它對筆記本很方便,但本身不是平行資料引擎——它的並行性只限於單一的 Python 程序。 因此,效能取決於讀取器和安裝在上面的引擎。 Azure Machine Learning 資料執行時的文件明確建議使用 Azure Machine Learning 資料執行環境,而非用戶端 Python 下載來訓練資料,並指出觀察到的儲存吞吐量限制,「當用戶端程式碼使用 Python 時因為全球解譯器鎖定(GIL)問題,無法從儲存裝置下載資料。」
使用 Azure Machine Learning Spark 進行 OneLake 上的大規模資料處理
OneLake 被設計為分析湖,端 abfss:// 點則是為 Spark 使用的平行分割讀取模式而建。 對於 TB 規模的 ETL、特徵工程或分散式訓練資料準備,建議優先使用 Azure Machine Learning Spark,而非 fsspec,並且最好在多節點叢集上執行:
Azure Machine Learning 中的 Serverless Spark 或 已連結的 Synapse Spark 集區——在 Azure Machine Learning 內執行 Spark 作業/筆記本,並透過
abfss://直接讀取 OneLake。 請參閱 Azure Machine Learning 中的 Apache Spark。Fabric Spark - 運行在 Fabric 內的 Spark 筆記本/工作擁有同一 Lakehouse 的頂級存取權,並可透過 OneLake 資料庫將精選輸出交接給 Azure Machine Learning。
以下範例示範在 Azure Machine Learning 計算中讀取 Spark 會話中的 lakehouse Delta 資料表:
df = (
spark.read.format("delta")
.load(
"abfss://<workspace_guid>@onelake.dfs.fabric.microsoft.com/"
"<item_guid>/Tables/<table-name>"
)
)
OneLake 與 Azure Machine Learning mltable
目前,透過 mltable 讀取以 OneLake 為後端的資料時,在以串流方式處理檔案時會失敗。 觀察到的誤差包括 ScriptExecution.StreamAccess.NotFound 和 Invalid argument (os error 22)。 Azure Machine Learning 計算資源可以透過 azureml-fsspec、pyarrow 或 Azure 儲存體 資料湖 SDK,使用相同的資料存放區和身分識別來解析及讀取 OneLake。
以 ML 表格代替,考慮以下其中一個替代方案:
- 讀取 OneLake 時,建議優先使用
uri_file/uri_folder資料資產,並以azureml-fsspec+ pyarrow / pandas / polars / DuckDB(單一節點)載入這些資料資產,或在abfss://上使用 Spark(分散式)。 Microsoft Learnmltable文件本身指出,對於簡單的 Parquet 資料夾或 CSV 檔案,uri_file/uri_folder是建議的選擇。 - 如果確實需要
mltable語意——最常見的情況是作為 AutoML 的輸入,因為其要求type: mltable——請先將資料暫存到 ADLS Gen2 帳戶,然後針對該位置建立mltable。mltable目前在 ADLS Gen2 上相當可靠。 - OneLake 捷徑模式(作為批次端點的一部分進行討論)非常適合 ML Table——同一個實體檔案存放在 ADLS Gen2 中(其中
mltable可運作),並透過捷徑呈現在 Fabric Lakehouse 中(Fabric 工具可看見它),無須複製。
mltable 整合了數項 uri_file / uri_folder 原生未提供的功能。 下表列出了直接閱讀 OneLake 時最接近的對應詞。
mltable 能力 |
替代方案 |
|---|---|
宣告式、可攜式讀取藍圖 (分隔符、編碼、標頭、分割區大小、欄位類型)會 MLTable 以檔案形式與資料一同存在 |
在 Python 中固定讀取設定(pyarrow.parquet.ParquetDataset、pandas.read_csv(...)、polars.scan_parquet(...)、duckdb.read_parquet(...)),並將該載入器模組納入原始碼控制 |
內建轉換於讀取時(filter、drop_columns、convert_column_types、take_random_sample) |
在你選擇的引擎中套用對應功能——polars / duckdb 延遲資料框同樣會將篩選與投影下推;在 abfss:// 上執行的 Spark 在大規模環境下也是如此 |
| 多來源路徑組合 ——一個資料表涵蓋多個檔案、資料夾、球狀模式,甚至儲存帳號 | 使用來自 fs.glob(...)、azureml-fsspec 或 Spark 的 pyarrow.dataset.dataset(paths) 的 spark.read.parquet(*paths),將路徑清單作為單一邏輯資料集來讀取 |
Azure Machine Learning 作業中的 eval_mount / eval_download 模式(在提交作業時從 MLTable 檔案解析路徑,僅掛接所參考的內容) |
在上游預先產出精選子集(由 Fabric notebook 或 Azure Machine Learning 預處理作業將其寫入專用的 /Files/curated/... 資料夾),並將其指向 uri_folder |
透過類型為 的資料資產對mltable(而不只是資料) |
在 Git 中將載入器腳本與模型程式碼一同進行版本控管,或將 uri_folder 資料資產與簽入在訓練腳本旁的小型載入模組配對 |
**AutoML 輸入—AutoML 指令 type: mltable (設定 AutoML 訓練) |
將資料暫存到 ADLS Gen2(來自 Lakehouse 的捷徑會維持單一實體副本),然後在該處建置 mltable |
若要在 OneLake 上進行自訂訓練和評分,請使用uri_file / uri_folder,再搭配你選擇的引擎(pyarrow / polars / duckdb單一節點,或 Azure Machine Learning 中的 Spark 分散式叢集)。 這些選項提供與 mltable 同等或更優吞吐量相同的功能能力。 對於 AutoML,請透過 ADLS Gen2 路由,直到 mltable 支援 OneLake。 你可以用 OneLake 的捷徑避免資料重複,同時在 Fabric 裡保留資料供其他用途使用。
Considerations
身分識別模型。 OneLake 採用 SaaS 身份模型,因此不會暴露訂閱 ID。 儲存帳號上不再使用 Azure 角色基礎存取控制(Azure RBAC),而是由目標湖屋上的 Fabric 工作區角色(管理員、成員、貢獻者、檢視者)來管理。 OneLake 資料儲存庫支援兩種憑證模式,這些模式在 建立資料儲存庫中有文件說明。 要設定資料儲存庫並存取 Fabric 湖屋,你需要一位擁有 Fabric 工作區貢獻者角色及 Azure Machine Learning 工作區管理員角色的使用者。
單一資料副本。 OneLake 的資料儲存庫與直接 ABFSS 存取維持了 OneLake 的「單一副本」原則。 批次端點的捷徑模式在邏輯上保留了這個原則,但需要一個 ADLS Gen2 帳號作為底層的實體儲存。
同區域部署。 將 Azure Machine Learning 工作區、運算能力和 Fabric 容量或 OneLake 區域置於同一區域,以避免跨區域的出口。