Incorporações de codificadores para Object2Vec
A página a seguir lista os formatos de solicitação de entrada e resposta de saída para obter inferência da incorporação do codificador do modelo Object2Vec do Amazon SageMaker.
Otimização de GPU: incorporações de codificador
Uma incorporação é um mapeamento de objetos discretos, como palavras, para vetores de números reais.
Devido à falta de memória de GPU, a variável de ambiente INFERENCE_PREFERRED_MODE
pode ser especificada para otimização se Formatos de dados para inferência em Object2Vec ou a rede de inferência de incorporação de codificador for carregada na GPU. Se a maior parte da inferência for para incorporações de codificador, especifique INFERENCE_PREFERRED_MODE=embedding
. Veja a seguir um exemplo de transformação em lotes usando 4 instâncias de p3.2xlarge que otimiza para inferência de incorporação de codificador:
transformer = o2v.transformer(instance_count=4, instance_type="ml.p2.xlarge", max_concurrent_transforms=2, max_payload=1, # 1MB strategy='MultiRecord', env={'INFERENCE_PREFERRED_MODE': 'embedding'}, # only useful with GPU output_path=output_s3_path)
Entrada: incorporações de codificador
Content-type: application/json; infer_max_seqlens=<FWD-LENGTH>,<BCK-LENGTH>
Em que <FWD-LENGTH> e <BCK-LENGTH> são inteiros no intervalo [1,5000] e definem os comprimentos máximos de sequência para o codificador para a frente e para trás.
{ "instances" : [ {"in0": [6, 17, 606, 19, 53, 67, 52, 12, 5, 10, 15, 10178, 7, 33, 652, 80, 15, 69, 821, 4]}, {"in0": [22, 1016, 32, 13, 25, 11, 5, 64, 573, 45, 5, 80, 15, 67, 21, 7, 9, 107, 4]}, {"in0": [774, 14, 21, 206]} ] }
Content-type: application/jsonlines; infer_max_seqlens=<FWD-LENGTH>,<BCK-LENGTH>
Em que <FWD-LENGTH> e <BCK-LENGTH> são inteiros no intervalo [1,5000] e definem os comprimentos máximos de sequência para o codificador para a frente e para trás.
{"in0": [6, 17, 606, 19, 53, 67, 52, 12, 5, 10, 15, 10178, 7, 33, 652, 80, 15, 69, 821, 4]} {"in0": [22, 1016, 32, 13, 25, 11, 5, 64, 573, 45, 5, 80, 15, 67, 21, 7, 9, 107, 4]} {"in0": [774, 14, 21, 206]}
Em ambos os formatos, você especifica apenas um tipo de entrada, ou “in0”
ou “in1.”
. O serviço de inferência invoca o codificador correspondente e gera as incorporações para cada uma das instâncias.
Saída: incorporações de codificador
Content-type: application/json
{ "predictions": [ {"embeddings":[0.057368703186511,0.030703511089086,0.099890425801277,0.063688032329082,0.026327300816774,0.003637571120634,0.021305780857801,0.004316598642617,0.0,0.003397724591195,0.0,0.000378780066967,0.0,0.0,0.0,0.007419463712722]}, {"embeddings":[0.150190666317939,0.05145975202322,0.098204270005226,0.064249359071254,0.056249320507049,0.01513972133398,0.047553978860378,0.0,0.0,0.011533712036907,0.011472506448626,0.010696629062294,0.0,0.0,0.0,0.008508535102009]} ] }
Content-type: application/jsonlines
{"embeddings":[0.057368703186511,0.030703511089086,0.099890425801277,0.063688032329082,0.026327300816774,0.003637571120634,0.021305780857801,0.004316598642617,0.0,0.003397724591195,0.0,0.000378780066967,0.0,0.0,0.0,0.007419463712722]} {"embeddings":[0.150190666317939,0.05145975202322,0.098204270005226,0.064249359071254,0.056249320507049,0.01513972133398,0.047553978860378,0.0,0.0,0.011533712036907,0.011472506448626,0.010696629062294,0.0,0.0,0.0,0.008508535102009]}
O comprimento de vetor das incorporações geradas pelo serviço de inferência é igual ao valor de um dos hiperparâmetros a seguir, que você especifica na ocasião do treinamento: enc0_token_embedding_dim
, enc1_token_embedding_dim
ou enc_dim
.