Meminta Entitas Silsilah - Amazon SageMaker

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Meminta Entitas Silsilah

Amazon SageMaker secara otomatis menghasilkan grafik entitas garis keturunan saat Anda menggunakannya. Anda dapat menanyakan data ini untuk menjawab berbagai pertanyaan. Anda dapat menanyakan entitas silsilah Anda ke:

  • Ambil semua kumpulan data yang masuk ke dalam pembuatan model.

  • Ambil semua pekerjaan yang masuk ke penciptaan titik akhir.

  • Ambil semua model yang menggunakan kumpulan data.

  • Ambil semua titik akhir yang menggunakan model.

  • Ambil titik akhir mana yang berasal dari kumpulan data tertentu.

  • Ambil eksekusi pipeline yang menciptakan pekerjaan pelatihan.

  • Mengambil hubungan antara entitas untuk investigasi, tata kelola, dan reproduktifitas.

  • Ambil semua uji coba hilir yang menggunakan artefak.

  • Ambil semua uji coba hulu yang menggunakan artefak.

  • Ambil daftar artefak yang menggunakan uri S3 yang disediakan.

  • Ambil artefak hulu yang menggunakan artefak dataset.

  • Ambil artefak hilir yang menggunakan artefak dataset.

  • Ambil dataset yang menggunakan artefak gambar.

  • Ambil tindakan yang menggunakan konteks.

  • Ambil pekerjaan pemrosesan yang menggunakan titik akhir.

  • Ambil pekerjaan transformasi yang menggunakan titik akhir.

  • Ambil komponen percobaan yang menggunakan titik akhir.

  • Ambil ARN untuk eksekusi pipeline yang terkait dengan grup paket model.

  • Ambil semua artefak yang menggunakan tindakan.

  • Ambil semua kumpulan data hulu yang menggunakan tindakan persetujuan paket model.

  • Ambil paket model dari tindakan persetujuan paket model.

  • Ambil konteks titik akhir hilir yang menggunakan titik akhir.

  • Ambil ARN untuk eksekusi pipeline yang terkait dengan komponen percobaan.

  • Ambil dataset yang menggunakan komponen trial.

  • Ambil model yang menggunakan komponen percobaan.

  • Jelajahi garis keturunan Anda untuk visualisasi.

Batasan
  • Kueri silsilah tidak tersedia di Wilayah berikut:

    • Afrika (Cape Town) — af-selatan

    • Asia Pasifik (Jakarta) — ap-southeast-3

    • Asia Pacific (Osaka) – ap-northeast-3

    • Eropa (Milan) — eu-south-1

    • Eropa (Spanyol) — eu-south-2

    • Israel (Tel Aviv) — il-central-1

  • Kedalaman maksimum hubungan untuk ditemukan saat ini terbatas pada 10.

  • Pemfilteran terbatas pada properti berikut: tanggal modifikasi terakhir, tanggal dibuat, jenis, dan jenis entitas garis keturunan.

Memulai dengan Menanyakan Entitas Lineage

Cara termudah untuk memulai adalah melalui:

Contoh berikut menunjukkan cara menggunakan LineageFilter API LineageQuery dan untuk membuat kueri guna menjawab pertanyaan tentang Grafik Lineage dan mengekstrak hubungan entitas untuk beberapa kasus penggunaan.

contoh Menggunakan LineageQuery API untuk menemukan asosiasi entitas
from sagemaker.lineage.context import Context, EndpointContext from sagemaker.lineage.action import Action from sagemaker.lineage.association import Association from sagemaker.lineage.artifact import Artifact, ModelArtifact, DatasetArtifact from sagemaker.lineage.query import ( LineageQuery, LineageFilter, LineageSourceEnum, LineageEntityEnum, LineageQueryDirectionEnum, ) # Find the endpoint context and model artifact that should be used for the lineage queries. contexts = Context.list(source_uri=endpoint_arn) context_name = list(contexts)[0].context_name endpoint_context = EndpointContext.load(context_name=context_name)
contoh Temukan semua kumpulan data yang terkait dengan titik akhir
# Define the LineageFilter to look for entities of type `ARTIFACT` and the source of type `DATASET`. query_filter = LineageFilter( entities=[LineageEntityEnum.ARTIFACT], sources=[LineageSourceEnum.DATASET] ) # Providing this `LineageFilter` to the `LineageQuery` constructs a query that traverses through the given context `endpoint_context` # and find all datasets. query_result = LineageQuery(sagemaker_session).query( start_arns=[endpoint_context.context_arn], query_filter=query_filter, direction=LineageQueryDirectionEnum.ASCENDANTS, include_edges=False, ) # Parse through the query results to get the lineage objects corresponding to the datasets dataset_artifacts = [] for vertex in query_result.vertices: dataset_artifacts.append(vertex.to_lineage_object().source.source_uri) pp.pprint(dataset_artifacts)
contoh Temukan model yang terkait dengan titik akhir
# Define the LineageFilter to look for entities of type `ARTIFACT` and the source of type `MODEL`. query_filter = LineageFilter( entities=[LineageEntityEnum.ARTIFACT], sources=[LineageSourceEnum.MODEL] ) # Providing this `LineageFilter` to the `LineageQuery` constructs a query that traverses through the given context `endpoint_context` # and find all datasets. query_result = LineageQuery(sagemaker_session).query( start_arns=[endpoint_context.context_arn], query_filter=query_filter, direction=LineageQueryDirectionEnum.ASCENDANTS, include_edges=False, ) # Parse through the query results to get the lineage objects corresponding to the model model_artifacts = [] for vertex in query_result.vertices: model_artifacts.append(vertex.to_lineage_object().source.source_uri) # The results of the `LineageQuery` API call return the ARN of the model deployed to the endpoint along with # the S3 URI to the model.tar.gz file associated with the model pp.pprint(model_artifacts)
contoh Temukan komponen uji coba yang terkait dengan titik akhir
# Define the LineageFilter to look for entities of type `TRIAL_COMPONENT` and the source of type `TRAINING_JOB`. query_filter = LineageFilter( entities=[LineageEntityEnum.TRIAL_COMPONENT], sources=[LineageSourceEnum.TRAINING_JOB], ) # Providing this `LineageFilter` to the `LineageQuery` constructs a query that traverses through the given context `endpoint_context` # and find all datasets. query_result = LineageQuery(sagemaker_session).query( start_arns=[endpoint_context.context_arn], query_filter=query_filter, direction=LineageQueryDirectionEnum.ASCENDANTS, include_edges=False, ) # Parse through the query results to get the ARNs of the training jobs associated with this Endpoint trial_components = [] for vertex in query_result.vertices: trial_components.append(vertex.arn) pp.pprint(trial_components)
contoh Mengubah titik fokus garis keturunan

LineageQueryDapat dimodifikasi agar berbeda start_arns yang mengubah titik fokus garis keturunan. Selain itu, LineageFilter dapat mengambil beberapa sumber dan entitas untuk memperluas cakupan kueri.

Berikut ini kami menggunakan model sebagai titik fokus garis keturunan dan menemukan titik akhir dan kumpulan data yang terkait dengannya.

# Get the ModelArtifact model_artifact_summary = list(Artifact.list(source_uri=model_package_arn))[0] model_artifact = ModelArtifact.load(artifact_arn=model_artifact_summary.artifact_arn) query_filter = LineageFilter( entities=[LineageEntityEnum.ARTIFACT], sources=[LineageSourceEnum.ENDPOINT, LineageSourceEnum.DATASET], ) query_result = LineageQuery(sagemaker_session).query( start_arns=[model_artifact.artifact_arn], # Model is the starting artifact query_filter=query_filter, # Find all the entities that descend from the model, i.e. the endpoint direction=LineageQueryDirectionEnum.DESCENDANTS, include_edges=False, ) associations = [] for vertex in query_result.vertices: associations.append(vertex.to_lineage_object().source.source_uri) query_result = LineageQuery(sagemaker_session).query( start_arns=[model_artifact.artifact_arn], # Model is the starting artifact query_filter=query_filter, # Find all the entities that ascend from the model, i.e. the datasets direction=LineageQueryDirectionEnum.ASCENDANTS, include_edges=False, ) for vertex in query_result.vertices: associations.append(vertex.to_lineage_object().source.source_uri) pp.pprint(associations)
contoh Menggunakan LineageQueryDirectionEnum.BOTH untuk menemukan hubungan naik dan turun

Ketika arah diatur keBOTH, kueri melintasi grafik untuk menemukan hubungan ascendant dan turunan. Traversal ini terjadi tidak hanya dari node awal, tetapi dari setiap node yang dikunjungi. Misalnya; jika pekerjaan pelatihan dijalankan dua kali dan kedua model yang dihasilkan oleh pekerjaan pelatihan diterapkan ke titik akhir, hasil kueri dengan arah diatur untuk BOTH menunjukkan kedua titik akhir. Ini karena gambar yang sama digunakan untuk pelatihan dan penerapan model. Karena gambar umum untuk model, start_arn dan kedua titik akhir, muncul di hasil kueri.

query_filter = LineageFilter( entities=[LineageEntityEnum.ARTIFACT], sources=[LineageSourceEnum.ENDPOINT, LineageSourceEnum.DATASET], ) query_result = LineageQuery(sagemaker_session).query( start_arns=[model_artifact.artifact_arn], # Model is the starting artifact query_filter=query_filter, # This specifies that the query should look for associations both ascending and descending for the start direction=LineageQueryDirectionEnum.BOTH, include_edges=False, ) associations = [] for vertex in query_result.vertices: associations.append(vertex.to_lineage_object().source.source_uri) pp.pprint(associations)
contoh Petunjuk dalam LineageQuery - ASCENDANTS vs. DESCENDANTS

Untuk memahami arah dalam Grafik Lineage, ambil grafik hubungan entitas berikut - Dataset -> Training Job -> Model -> Endpoint

Titik akhir adalah keturunan dari model, dan model adalah keturunan dari dataset. Demikian pula, model adalah ascendant dari endpoint. directionParameter dapat digunakan untuk menentukan apakah kueri harus mengembalikan entitas yang merupakan turunan atau ascendants dari entitas di. start_arns Jika start_arns berisi model dan arahnyaDESCENDANTS, kueri mengembalikan titik akhir. Jika arahnyaASCENDANTS, kueri mengembalikan dataset.

# In this example, we'll look at the impact of specifying the direction as ASCENDANT or DESCENDANT in a `LineageQuery`. query_filter = LineageFilter( entities=[LineageEntityEnum.ARTIFACT], sources=[ LineageSourceEnum.ENDPOINT, LineageSourceEnum.MODEL, LineageSourceEnum.DATASET, LineageSourceEnum.TRAINING_JOB, ], ) query_result = LineageQuery(sagemaker_session).query( start_arns=[model_artifact.artifact_arn], query_filter=query_filter, direction=LineageQueryDirectionEnum.ASCENDANTS, include_edges=False, ) ascendant_artifacts = [] # The lineage entity returned for the Training Job is a TrialComponent which can't be converted to a # lineage object using the method `to_lineage_object()` so we extract the TrialComponent ARN. for vertex in query_result.vertices: try: ascendant_artifacts.append(vertex.to_lineage_object().source.source_uri) except: ascendant_artifacts.append(vertex.arn) print("Ascendant artifacts : ") pp.pprint(ascendant_artifacts) query_result = LineageQuery(sagemaker_session).query( start_arns=[model_artifact.artifact_arn], query_filter=query_filter, direction=LineageQueryDirectionEnum.DESCENDANTS, include_edges=False, ) descendant_artifacts = [] for vertex in query_result.vertices: try: descendant_artifacts.append(vertex.to_lineage_object().source.source_uri) except: # Handling TrialComponents. descendant_artifacts.append(vertex.arn) print("Descendant artifacts : ") pp.pprint(descendant_artifacts)
contoh Fungsi pembantu SDK untuk membuat kueri silsilah lebih mudah

KelasEndpointContext,ModelArtifact, dan DatasetArtifact memiliki fungsi pembantu yang merupakan pembungkus LineageQuery API untuk membuat kueri garis keturunan tertentu lebih mudah dimanfaatkan. Contoh berikut menunjukkan bagaimana menggunakan fungsi pembantu ini.

# Find all the datasets associated with this endpoint datasets = [] dataset_artifacts = endpoint_context.dataset_artifacts() for dataset in dataset_artifacts: datasets.append(dataset.source.source_uri) print("Datasets : ", datasets) # Find the training jobs associated with the endpoint training_job_artifacts = endpoint_context.training_job_arns() training_jobs = [] for training_job in training_job_artifacts: training_jobs.append(training_job) print("Training Jobs : ", training_jobs) # Get the ARN for the pipeline execution associated with this endpoint (if any) pipeline_executions = endpoint_context.pipeline_execution_arn() if pipeline_executions: for pipeline in pipelines_executions: print(pipeline) # Here we use the `ModelArtifact` class to find all the datasets and endpoints associated with the model dataset_artifacts = model_artifact.dataset_artifacts() endpoint_contexts = model_artifact.endpoint_contexts() datasets = [dataset.source.source_uri for dataset in dataset_artifacts] endpoints = [endpoint.source.source_uri for endpoint in endpoint_contexts] print("Datasets associated with this model : ") pp.pprint(datasets) print("Endpoints associated with this model : ") pp.pprint(endpoints) # Here we use the `DatasetArtifact` class to find all the endpoints hosting models that were trained with a particular dataset # Find the artifact associated with the dataset dataset_artifact_arn = list(Artifact.list(source_uri=training_data))[0].artifact_arn dataset_artifact = DatasetArtifact.load(artifact_arn=dataset_artifact_arn) # Find the endpoints that used this training dataset endpoint_contexts = dataset_artifact.endpoint_contexts() endpoints = [endpoint.source.source_uri for endpoint in endpoint_contexts] print("Endpoints associated with the training dataset {}".format(training_data)) pp.pprint(endpoints)
contoh Mendapatkan visualisasi grafik Lineage

Kelas pembantu Visualizer disediakan di sameple notebook visualizer.py untuk membantu memplot grafik garis keturunan. Saat respons kueri dirender, grafik dengan hubungan garis keturunan dari ditampilkan. StartArns Dari visualisasi menunjukkan hubungan dengan entitas garis keturunan lain yang ditampilkan dalam tindakan API. StartArns query_lineage

# Graph APIs # Here we use the boto3 `query_lineage` API to generate the query response to plot. from visualizer import Visualizer query_response = sm_client.query_lineage( StartArns=[endpoint_context.context_arn], Direction="Ascendants", IncludeEdges=True ) viz = Visualizer() viz.render(query_response, "Endpoint") query_response = sm_client.query_lineage( StartArns=[model_artifact.artifact_arn], Direction="Ascendants", IncludeEdges=True ) viz.render(query_response, "Model")