Cloudwatch 日志 AWS

问题描述 投票:0回答:2

我尝试在 AWS Sagemaker 上托管模型,当我部署终端节点时,我想查看错误。为了查看它们,过去几周我一直在检查 CloudWatch 日志,但现在它们没有出现。

检查再检查再检查,IAM角色,使用的是哪个角色,拥有哪些权限。我假设端点正在使用的角色是在创建模型期间分配给模型的角色。还尝试通过 CLI 创建端点,但这没有改变任何东西。

尝试创建新模型(相同的工件和推理代码,只是一个官方模型)并将该新模型用于端点。那没有用。尝试在试验之间留出时间以确保最大会话已过期。但这没有改变什么。尝试过不同地区。那没有用。尝试了不同的模型(不同的工件和推理代码)。那没有用。不太确定此时我还有什么选择。

amazon-web-services amazon-cloudwatch amazon-sagemaker amazon-cloudwatchlogs
2个回答
0
投票

如果您没有看到 SageMaker 端点的 CloudWatch 日志,您可以检查以下几项内容:

IAM 角色权限: 确保分配给您的 SageMaker 终端节点的 IAM 角色具有将日志写入 CloudWatch 所需的权限。该角色应附加 AmazonCloudWatchFullAccess 策略。

检查 CloudWatch 日志组: 验证 CloudWatch 中是否存在终端节点的日志组。日志组通常命名为 /aws/sagemaker/Endpoints/YourEndpointName。如果它不存在,则可能表明端点创建期间出现问题。

代码中的日志记录设置:在推理代码中,确保您已正确设置日志记录。您可能正在使用 boto3 等日志记录库将日志发送到 CloudWatch。确保日志记录配置准确。

使用 boto3 的示例:

import boto3
import logging

logger = logging.getLogger()
logger.setLevel(logging.INFO)

def lambda_handler(event, context):
    logger.info("Your log message here.")
    # rest of your code

0
投票
import torch
import boto3
import logging
from accelerate import init_empty_weights
from transformers import pipeline, AutoTokenizer, LlamaForCausalLM, AutoConfig, AutoModelForCausalLM

logger = logging.getLogger()
logger.setLevel(logging.INFO)


def model_fn(model_dir):
    try:
        model_name = "johaanm/grader-public"  # Replace with your actual model name
        save_folder = model_dir  # This should be the path to your quantized model directory

        # Initialize an empty model  with the architecture
        with init_empty_weights():
            empty_model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16)
        empty_model.tie_weights()

        # Load the quantized model weights from save_folder
        quantized_model = AutoModelForCausalLM.from_pretrained(save_folder, torch_dtype=torch.float16,
                                                               device_map="auto")

        tokenizer = AutoTokenizer.from_pretrained(save_folder)

        return quantized_model, tokenizer
    except Exception as e:
        logger.info(f"Error in model_fn: {e}")
        raise

def strip_prompt_from_output(prompt, output):
    similar logging logic

def input_fn(request_body, request_content_type):
    similar logging logic

def predict_fn(input_data, model_and_tokenizer):
    similar logging logic

def output_fn(prediction_output, response_content_type):
   similar logging logic
© www.soinside.com 2019 - 2024. All rights reserved.