Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
L'agente Edge Manager può caricare più modelli alla volta e fare inferenze con i modelli caricati sui dispositivi edge. Il numero di modelli che l'agente può caricare è determinato dalla memoria disponibile sul dispositivo. L'agente convalida la firma del modello e carica in memoria tutti gli artefatti prodotti dal processo di creazione di pacchetti edge. Questa fase richiede l'installazione di tutti i certificati richiesti descritti nelle fasi precedenti insieme al resto dell'installazione binaria. Se la firma del modello non può essere convalidata, il relativo caricamento non riesce con il codice restituito e il motivo appropriati.
SageMaker L'agente Edge Manager fornisce un elenco di Model Management APIs che implementano il piano di controllo e il piano dati APIs sui dispositivi edge. Oltre a questa documentazione, consigliamo di esaminare l'implementazione client di esempio che mostra l'uso canonico di quanto descritto di seguito. APIs
Il file proto
è disponibile come parte degli elementi di rilascio (all'interno del tarball di rilascio). In questo documento, elenchiamo e descriviamo l'uso di APIs list in questo proto
file.
Nota
Esiste una one-to-one mappatura per questi aspetti APIs nella versione di Windows e un codice di esempio per un'applicazione implementata in C# è condiviso con gli artefatti di rilascio per Windows. Le istruzioni riportate di seguito riguardano l'esecuzione dell'agente come processo autonomo, applicabile agli artefatti di rilascio per Linux.
Estrai l'archivio in base al tuo sistema operativo. Dove VERSION
è suddiviso in tre componenti: <MAJOR_VERSION>.<YYYY-MM-DD>-<SHA-7>
. vedere Installazione dell'agente Edge Manager per informazioni su come ottenere la versione di rilascio (<MAJOR_VERSION>
), il timestamp dell'elemento di rilascio (<YYYY-MM-DD>
) e l'ID di commit del repository (SHA-7
).
L'archivio zip può essere estratto con il comando:
tar -xvzf
<VERSION>
.tgz
La gerarchia degli artefatti di rilascio (dopo l'estrazione dell'archivio tar/zip
) è mostrata di seguito. Il file proto
dell'agente è disponibile in api/
.
0.20201205.7ee4b0b ├── bin │ ├── sagemaker_edge_agent_binary │ └── sagemaker_edge_agent_client_example └── docs ├── api │ └── agent.proto ├── attributions │ ├── agent.txt │ └── core.txt └── examples └── ipc_example ├── CMakeLists.txt ├── sagemaker_edge_client.cc ├── sagemaker_edge_client_example.cc ├── sagemaker_edge_client.hh ├── sagemaker_edge.proto ├── README.md ├── shm.cc ├── shm.hh └── street_small.bmp
Argomenti
Caricamento dei modelli
L'agente Edge Manager supporta il caricamento di più modelli. Questa API convalida la firma del modello e carica in memoria tutti gli artefatti prodotti dall'operazione EdgePackagingJob
. Questa fase richiede l'installazione di tutti i certificati richiesti insieme al resto dell'installazione binaria dell'agente. Se la firma del modello non può essere convalidata, questa fase non riesce, indicando un codice restituito appropriato e messaggi di errore nel log.
// perform load for a model // Note: // 1. currently only local filesystem paths are supported for loading models. // 2. multiple models can be loaded at the same time, as limited by available device memory // 3. users are required to unload any loaded model to load another model. // Status Codes: // 1. OK - load is successful // 2. UNKNOWN - unknown error has occurred // 3. INTERNAL - an internal error has occurred // 4. NOT_FOUND - model doesn't exist at the url // 5. ALREADY_EXISTS - model with the same name is already loaded // 6. RESOURCE_EXHAUSTED - memory is not available to load the model // 7. FAILED_PRECONDITION - model is not compiled for the machine. // rpc LoadModel(LoadModelRequest) returns (LoadModelResponse);
// // request for LoadModel rpc call // message LoadModelRequest { string url = 1; string name = 2; // Model name needs to match regex "^[a-zA-Z0-9](-*[a-zA-Z0-9])*$" }
Scaricare il modello
Scarica un modello caricato in precedenza. Viene identificato tramite l'alias del modello fornito durante loadModel
. Se l'alias non viene trovato o il modello non viene caricato, restituisce un errore.
// // perform unload for a model // Status Codes: // 1. OK - unload is successful // 2. UNKNOWN - unknown error has occurred // 3. INTERNAL - an internal error has occurred // 4. NOT_FOUND - model doesn't exist // rpc UnLoadModel(UnLoadModelRequest) returns (UnLoadModelResponse);
// // request for UnLoadModel rpc call // message UnLoadModelRequest { string name = 1; // Model name needs to match regex "^[a-zA-Z0-9](-*[a-zA-Z0-9])*$" }
Elenca modelli
Elenca tutti i modelli caricati e i relativi alias.
// // lists the loaded models // Status Codes: // 1. OK - unload is successful // 2. UNKNOWN - unknown error has occurred // 3. INTERNAL - an internal error has occurred // rpc ListModels(ListModelsRequest) returns (ListModelsResponse);
// // request for ListModels rpc call // message ListModelsRequest {}
Descrivi modello
Descrive un modello caricato sull'agente.
// // Status Codes: // 1. OK - load is successful // 2. UNKNOWN - unknown error has occurred // 3. INTERNAL - an internal error has occurred // 4. NOT_FOUND - model doesn't exist at the url // rpc DescribeModel(DescribeModelRequest) returns (DescribeModelResponse);
// // request for DescribeModel rpc call // message DescribeModelRequest { string name = 1; }
Acquisisci i dati
Consente all'applicazione client di acquisire tensori di input e output nel bucket Amazon S3 e, facoltativamente, gli ausiliari. L'applicazione client dovrebbe passare un ID di acquisizione univoco insieme a ogni chiamata a questa API. Questo può essere utilizzato in seguito per eseguire una query sullo stato dell'acquisizione.
// // allows users to capture input and output tensors along with auxiliary data. // Status Codes: // 1. OK - data capture successfully initiated // 2. UNKNOWN - unknown error has occurred // 3. INTERNAL - an internal error has occurred // 5. ALREADY_EXISTS - capture initiated for the given capture_id // 6. RESOURCE_EXHAUSTED - buffer is full cannot accept any more requests. // 7. OUT_OF_RANGE - timestamp is in the future. // 8. INVALID_ARGUMENT - capture_id is not of expected format. // rpc CaptureData(CaptureDataRequest) returns (CaptureDataResponse);
enum Encoding { CSV = 0; JSON = 1; NONE = 2; BASE64 = 3; } // // AuxilaryData represents a payload of extra data to be capture along with inputs and outputs of inference // encoding - supports the encoding of the data // data - represents the data of shared memory, this could be passed in two ways: // a. send across the raw bytes of the multi-dimensional tensor array // b. send a SharedMemoryHandle which contains the posix shared memory segment id and // offset in bytes to location of multi-dimensional tensor array. // message AuxilaryData { string name = 1; Encoding encoding = 2; oneof data { bytes byte_data = 3; SharedMemoryHandle shared_memory_handle = 4; } } // // Tensor represents a tensor, encoded as contiguous multi-dimensional array. // tensor_metadata - represents metadata of the shared memory segment // data_or_handle - represents the data of shared memory, this could be passed in two ways: // a. send across the raw bytes of the multi-dimensional tensor array // b. send a SharedMemoryHandle which contains the posix shared memory segment // id and offset in bytes to location of multi-dimensional tensor array. // message Tensor { TensorMetadata tensor_metadata = 1; //optional in the predict request oneof data { bytes byte_data = 4; // will only be used for input tensors SharedMemoryHandle shared_memory_handle = 5; } } // // request for CaptureData rpc call // message CaptureDataRequest { string model_name = 1; string capture_id = 2; //uuid string Timestamp inference_timestamp = 3; repeated Tensor input_tensors = 4; repeated Tensor output_tensors = 5; repeated AuxilaryData inputs = 6; repeated AuxilaryData outputs = 7; }
Ottieni lo stato dell'acquisizione
A seconda dei modelli caricati, i tensori di input e output possono essere grandi (per molti dispositivi edge). L'acquisizione nel cloud può richiedere molto tempo. Quindi CaptureData()
viene implementato come operazione asincrona. Un ID di acquisizione è un identificatore univoco fornito dal client durante la chiamata di acquisizione dati, questo ID può essere utilizzato per interrogare lo stato della chiamata asincrona.
// // allows users to query status of capture data operation // Status Codes: // 1. OK - data capture successfully initiated // 2. UNKNOWN - unknown error has occurred // 3. INTERNAL - an internal error has occurred // 4. NOT_FOUND - given capture id doesn't exist. // rpc GetCaptureDataStatus(GetCaptureDataStatusRequest) returns (GetCaptureDataStatusResponse);
// // request for GetCaptureDataStatus rpc call // message GetCaptureDataStatusRequest { string capture_id = 1; }
Prevedi
L'API predict
esegue l'inferenza su un modello caricato in precedenza. Accetta una richiesta sotto forma di tensore che viene inserito direttamente nella rete neurale. L'output è il tensore di uscita (o scalare) del modello. Questa è una chiamata di blocco.
// // perform inference on a model. // // Note: // 1. users can chose to send the tensor data in the protobuf message or // through a shared memory segment on a per tensor basis, the Predict // method with handle the decode transparently. // 2. serializing large tensors into the protobuf message can be quite expensive, // based on our measurements it is recommended to use shared memory of // tenors larger than 256KB. // 3. SMEdge IPC server will not use shared memory for returning output tensors, // i.e., the output tensor data will always send in byte form encoded // in the tensors of PredictResponse. // 4. currently SMEdge IPC server cannot handle concurrent predict calls, all // these call will be serialized under the hood. this shall be addressed // in a later release. // Status Codes: // 1. OK - prediction is successful // 2. UNKNOWN - unknown error has occurred // 3. INTERNAL - an internal error has occurred // 4. NOT_FOUND - when model not found // 5. INVALID_ARGUMENT - when tenors types mismatch // rpc Predict(PredictRequest) returns (PredictResponse);
// request for Predict rpc call // message PredictRequest { string name = 1; repeated Tensor tensors = 2; } // // Tensor represents a tensor, encoded as contiguous multi-dimensional array. // tensor_metadata - represents metadata of the shared memory segment // data_or_handle - represents the data of shared memory, this could be passed in two ways: // a. send across the raw bytes of the multi-dimensional tensor array // b. send a SharedMemoryHandle which contains the posix shared memory segment // id and offset in bytes to location of multi-dimensional tensor array. // message Tensor { TensorMetadata tensor_metadata = 1; //optional in the predict request oneof data { bytes byte_data = 4; // will only be used for input tensors SharedMemoryHandle shared_memory_handle = 5; } } // // Tensor represents a tensor, encoded as contiguous multi-dimensional array. // tensor_metadata - represents metadata of the shared memory segment // data_or_handle - represents the data of shared memory, this could be passed in two ways: // a. send across the raw bytes of the multi-dimensional tensor array // b. send a SharedMemoryHandle which contains the posix shared memory segment // id and offset in bytes to location of multi-dimensional tensor array. // message Tensor { TensorMetadata tensor_metadata = 1; //optional in the predict request oneof data { bytes byte_data = 4; // will only be used for input tensors SharedMemoryHandle shared_memory_handle = 5; } } // // TensorMetadata represents the metadata for a tensor // name - name of the tensor // data_type - data type of the tensor // shape - array of dimensions of the tensor // message TensorMetadata { string name = 1; DataType data_type = 2; repeated int32 shape = 3; } // // SharedMemoryHandle represents a posix shared memory segment // offset - offset in bytes from the start of the shared memory segment. // segment_id - shared memory segment id corresponding to the posix shared memory segment. // size - size in bytes of shared memory segment to use from the offset position. // message SharedMemoryHandle { uint64 size = 1; uint64 offset = 2; uint64 segment_id = 3; }