在 SageMaker AI 上满足 EU AI Act 的 LLM 微调要求

2026 年 11 月:本文已审核并更新,以确保准确性。
根据 EU AI Act,对大型语言模型(LLM)进行微调的组织在某些情况下可能成为修改后模型的提供者,从而需要承担自身的义务。欧盟委员会的指南使用以浮点运算(FLOPs)计量的训练算力,作为判断这种情况何时发生的指示性标准。随着客户越来越多地针对特定领域用例微调 LLM,我们经常听到一个常见问题:我如何知道我的训练任务是否会触发新的监管义务?
Amazon SageMaker AI 提供托管机器学习(ML)服务,用于构建、训练和部署模型。该解决方案使用 Amazon SageMaker Training 任务在全托管基础设施上运行微调工作负载。SageMaker Training 任务负责资源调配、扩缩容和集群管理,内置对分布式训练的支持,与 AWS CloudTrail 和 Amazon CloudWatch 集成以实现治理,并在训练完成后自动停用计算资源。Fine-Tuning FLOPs Meter 通过专为合规跟踪构建的功能扩展了这些能力,并可集成到你现有的 SageMaker AI 管道中。
在本文中,我们将展示如何使用 Amazon SageMaker AI 上的开源 Fine-Tuning FLOPs Meter 工具包,在 LLM 微调期间设置 FLOPs 跟踪。你将了解如何通过单个配置标志测量微调任务的训练算力,将其与委员会指南中的阈值进行比较,并保留结果的 JSON 记录。
针对通用人工智能(GPAI)模型提供者的《欧盟人工智能法案》义务自2025年8月2日起已开始适用。欧盟委员会可从2026年8月2日起执行这些义务,包括处以罚款。对于在2025年8月2日之前投放市场的模型,其提供者最迟须在2027年8月2日前合规。如果你正在微调一个大语言模型(LLM),请考虑你的修改是否可能使你的角色从下游用户(使用现有模型而未进行实质性修改的组织)变为 GPAI 模型提供者(对模型合规性负有法律责任的组织)。该法案本身并未明确规定这种情况何时发生,但欧盟委员会于2025年7月发布的关于 GPAI 义务范围的指南给出了指示性标准。
根据指南,只有当修改显著改变模型的通用性、能力或系统性风险时,修改方才成为提供者。作为一个指示性标准,指南使用用于修改的算力:超过训练原始模型所用算力的三分之一,通常称为三分之一规则。这些指南不具有法律约束力,但欧盟委员会表示将依据这些指南进行执法。本文中的阈值来自这些指南,而非该法案本身。欧盟委员会还评估了于 2025 年 7 月发布的自愿性《通用人工智能行为准则》,认为这是提供者证明合规的充分方式。大多数组织使用下表中的情景 2,因为模型提供者很少公布确切的训练 FLOPs。除非你有来自模型提供者的有记录的预训练算力,否则指南给出 3.3×10²² FLOPs 的默认阈值。欧盟委员会的指南描述了三种情景和阈值:
Fine-Tuning FLOPs Meter 会根据你是否提供 PRETRAIN_FLOPS 环境变量,自动判断适用哪种情景。为了帮你快速确定适用哪条阈值路径,请使用以下决策流程:
步骤 1:你知道你的基础模型的预训练 FLOPs 吗?
步骤 2:评估预训练算力规模
如果你知道你的预训练算力,请将其与以下数量级进行比较:
预训练算力是否 ≥ 10²⁵ FLOPs?
预训练算力是否 ≥ 10²³ FLOPs?
例如,微调 Llama-3-70B(预训练算力估计至少为 1.5×10²⁴ FLOPs)会将阈值设为 4.5×10²³ FLOPs。根据欧盟委员会的指南,超过该阈值表明你可能成为修改后模型的提供者。关于这种情况下需要考虑什么,请见本文后面的“如果超过阈值怎么办?”。
《人工智能法案》在两个地方设定了罚款。第99条为 AI 系统的运营者设定了分级最高罚款。每一级均为固定金额与全球年营业额的一定比例中的较高者:对于被禁止的 AI 实践,最高为 3500 万欧元或 7%;对于大多数其他义务,最高为 1500 万欧元或 3%;对于向公告机构或国家主管机关提供不正确、不完整或误导性信息,最高为 750 万欧元或 1%。更低的上限适用于中小企业(SMEs)和小型中盘企业。对 GPAI 模型提供者的罚款在第101条中单独规定:自2026年8月2日起,欧盟委员会可处以最高 1500 万欧元或全球年营业额 3% 的罚款,以较高者为准。
这些阈值带来三项合规挑战:
计算错误可能导致对作业是否超过阈值得出错误结论。Fine-Tuning FLOPs Meter 可自动执行跟踪流程,从而应对这些挑战。
Fine-Tuning FLOPs Meter 是一个开源工具包,可在 Amazon SageMaker Generative AI recipes 仓库中获取,并能集成到 Amazon SageMaker AI 上的 Hugging Face 训练工作流中。它会跟踪整个微调生命周期中的计算资源。下图展示了合规工作流。
图 1. Fine-Tuning FLOPs Meter 合规工作流
该工具包覆盖微调生命周期的三个阶段,其中运行时追踪是核心能力。
第一阶段:一个可选的训练前估算工具,你可以在启动作业之前运行它,比较不同训练方法(LoRA、Spectrum、Full)的预期 FLOPs。
第二阶段:运行时追踪,这是主要功能,它使用 Hugging Face TrainerCallback,在训练过程中结合基于架构的分析和通过 NVIDIA Management Library(NVML)实现的基于硬件的 GPU 监控,实时计算 FLOPs。
第三阶段:训练后审计追踪会自动以 JSON 格式存储完整的合规指标。你可以将结果持久化到 Amazon Simple Storage Service(Amazon S3)或 Amazon DynamoDB。
你只需一行配置(compute_flops: true)即可启用。FLOPs Meter 具备参数高效感知能力,通过增强的公式对 full、LoRA 和 Spectrum 微调方式进行准确估算。它会把计算指标写入 JSON 文件,并执行自动化阈值比较,帮助确定适用的阈值,并标记你的微调作业是否超出该阈值。
以下小节介绍 FLOPs 是如何计算的,以及该追踪功能如何与你在 Amazon SageMaker AI 上的训练工作流集成。
在运行 FLOPs Meter 演练之前,你必须完成以下前提条件。
为 SageMaker AI 提交以下配额增加请求。对于此用例,你至少需要 1 个 ml.g5.4xlarge 实例(配备 1 块 NVIDIA A10G GPU)。在 Service Quotas 控制台中,请求用于训练作业的 SageMaker AI 配额 G5 实例(ml.g5.4xlarge):1。
创建一个 AWS Identity and Access Management (IAM) [角色](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-roles.html#:~:text=the%20following%20procedures.-%5B%E2%80%A6%5Dxecution%20role,-Use%20the%20following%20(),并为其附加托管策略 AmazonSageMakerFullAccess 和 AmazonS3FullAccess,以便授予 SageMaker AI 运行这些示例所需的访问权限。
将以下策略作为信任关系分配给您的 IAM 角色:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "Service": [ "sagemaker.amazonaws.com" ] }, "Action": "sts:AssumeRole" } ] } (可选)创建一个 Amazon SageMaker Studio 域(请参阅 Use quick setup for Amazon SageMaker AI),以便使用上述角色访问 Jupyter notebooks。您也可以在本地环境中使用 JupyterLab。
这些权限授予了广泛的访问权限,不建议在生产环境中使用。有关定义更细粒度权限的指导,请参阅 SageMaker AI Developer Guide。
为进行合规报告,请使用分析方法(Flops_architecture)作为主要指标。该工具包还会计算基于硬件的上限,以便进行保守报告。两种方法都会自动运行。以下各节将介绍实现细节。
该委员会的指南(A.2.1 节)描述了两种估算训练算力的方法:
该委员会的指南给出了稠密 Transformer 的以下近似公式:
C ≈ 6 × P × D
其中 P 是参数量,D 是训练 Token 数。这里假设的是全量微调,即所有参数都可训练。
一个增强版公式则考虑了参数高效方法:
F_ft = (4 × N_total + 2 × N_trainable) × tokens_processed
具体拆解如下:
原文较长,译文为节选;译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。
查看英文原文(Navigating EU AI Act requirements for LLM fine-tuning on Amazon SageMaker AI)
November 2026: This post was reviewed and updated for accuracy.
Under the EU AI Act, organizations that fine-tune large language models (LLMs) can in some cases become providers of the modified model, with obligations of their own. The European Commission’s guidelines use training compute, measured in floating-point operations (FLOPs), as an indicative criterion for when this happens. As customers increasingly fine-tune LLMs for domain-specific use cases, we hear a common question: how do I know if my training job triggers new regulatory obligations?
Amazon SageMaker AI provides a managed machine learning (ML) service for building, training, and deploying models. This solution uses Amazon SageMaker Training jobs to run fine-tuning workloads on fully managed infrastructure. SageMaker Training jobs handle resource provisioning, scaling, and cluster management, with built-in support for distributed training, integration with AWS CloudTrail and Amazon CloudWatch for governance, and automatic decommissioning of compute resources after training completes. The Fine-Tuning FLOPs Meter extends these capabilities with purpose-built compliance tracking that integrates into your existing SageMaker AI pipelines.
In this post, we show you how to set up FLOPs tracking during LLM fine-tuning using the open source Fine-Tuning FLOPs Meter toolkit on Amazon SageMaker AI. You learn how to measure the training compute of a fine-tuning job with a single configuration flag, compare it with the thresholds in the Commission’s guidelines, and keep a JSON record of the results.
EU AI Act and FLOPs tracking requirements
The EU AI Act obligations for providers of general-purpose artificial intelligence (GPAI) models have applied since August 2, 2025. The European Commission can enforce them, including through fines, from August 2, 2026. Providers of models placed on the market before August 2, 2025 have until August 2, 2027 to comply. If you’re fine-tuning an LLM, consider whether your modifications could change your role from a downstream user (an organization that uses an existing model without substantial modification) to a GPAI model provider (an organization legally responsible for a model’s compliance). The Act itself doesn’t specify when this happens, but the European Commission’s guidelines on the scope of GPAI obligations, published in July 2025, give indicative criteria.
According to the guidelines, a modifier becomes the provider only if the modification significantly changes the model’s generality, capabilities, or systemic risk. As an indicative criterion, the guidelines use the compute spent on the modification: more than one-third of the compute used to train the original model, often called the one-third rule. The guidelines aren’t legally binding, but the Commission states that it will base its enforcement on them. The thresholds in this post come from these guidelines, not from the Act itself. The Commission has also assessed the voluntary General-Purpose AI Code of Practice, published in July 2025, as an adequate way for providers to demonstrate compliance. Most organizations use scenario 2 in the following table because model providers rarely publish exact training FLOPs. Unless you have documented pretraining compute from your model provider, the guidelines give a default threshold of 3.3×10²² FLOPs. The Commission’s guidelines describe three scenarios and thresholds:
| Scenario | Threshold |
| Pretraining compute is known and ≥ 10²³ FLOPs | 30% of the actual pretraining compute |
| Pretraining compute is unknown or < 10²³ FLOPs | Default threshold of 3.3×10²² FLOPs |
| Systemic Risk Models (Pre-training FLOPs ≥ 10²⁵ FLOPs) | 3.3×10²⁴ FLOPs (if base compute is unknown) |
The Fine-Tuning FLOPs Meter automatically determines which scenario applies based on whether you provide the PRETRAIN_FLOPS environment variable. To help you quickly determine which threshold path applies, use the following decision flow:
Step 1: Do you know your base model’s pretraining FLOPs?
- No: Proceed directly to the Default Threshold of 3.3×10²² FLOPs.
- Yes: Move to the next evaluation step.
Step 2: Evaluate pretraining compute scale
If you know your pretraining compute, compare it against the following orders of magnitude:
-
Is pretraining compute ≥ 10²⁵ FLOPs?
- Yes: You fall under the Systemic Risk Threshold. Use a threshold of 3.3×10²⁴ FLOPs.
- No: Move to the next question.
-
Is pretraining compute ≥ 10²³ FLOPs?
- Yes: Use a Relative Threshold of 30% of actual pretraining compute.
- No: Proceed to the Default Threshold of 3.3×10²² FLOPs.
For example, fine-tuning Llama-3-70B (pretrained with an estimated minimum of 1.5×10²⁴ FLOPs) sets the threshold at 4.5×10²³ FLOPs. Under the Commission’s guidelines, exceeding this threshold is an indication that you may become the provider of the modified model. For what to consider in that case, see What if you exceed the threshold? later in this post.
The AI Act sets fines in two places. Article 99 sets tiered maximum fines for operators of AI systems. Each tier is the higher of a fixed amount and a share of worldwide annual turnover: up to €35 million or 7% for prohibited AI practices, up to €15 million or 3% for most other obligations, and up to €7.5 million or 1% for supplying incorrect, incomplete, or misleading information to notified bodies or national authorities. Lower caps apply to small and medium-sized enterprises (SMEs) and small mid-cap enterprises. Fines for providers of GPAI models are set separately in Article 101: the European Commission can impose fines of up to €15 million or 3% of worldwide annual turnover, whichever is higher, from August 2, 2026.
The challenge of manual FLOPs tracking
These thresholds present three compliance challenges:
- FLOPs formulas are complex and differ depending on whether you’re doing full fine-tuning or using parameter-efficient methods (training approaches like Low-Rank Adaptation (LoRA) that update only a small subset of model parameters).
- The applicable threshold is hard to determine because pretraining compute figures are rarely published.
- Maintaining an audit trail (a permanent record of compliance metrics for regulatory review) across multiple training jobs adds operational overhead.
Incorrect calculations can lead to the wrong conclusion about whether your job exceeds the threshold. The Fine-Tuning FLOPs Meter automates the tracking process, addressing these challenges.
Solution overview
The Fine-Tuning FLOPs Meter is an open source toolkit, available in the Amazon SageMaker Generative AI recipes repository, that integrates into Hugging Face training workflows on Amazon SageMaker AI. It tracks computational resources across the entire fine-tuning lifecycle. The following diagram illustrates the compliance workflow.
The toolkit covers three stages of the fine-tuning lifecycle, with runtime tracking as the core capability.
First stage: an optional pre-training estimation utility that you can run to compare expected FLOPs across training methods (LoRA, Spectrum, Full) before you launch a job.
Second stage: runtime tracking, the main feature, uses a Hugging Face TrainerCallback to calculate FLOPs in real time during training using both architecture-based analytics and hardware-based GPU monitoring through NVIDIA Management Library (NVML).
Third stage: a post-training audit trail automatically stores complete compliance metrics in JSON format. You can persist results to Amazon Simple Storage Service (Amazon S3) or Amazon DynamoDB.
You can opt in with a single configuration line (compute_flops: true). The FLOPs Meter includes parameter-efficient awareness using an enhanced formula to accurately estimate for full, LoRA, and Spectrum fine-tuning approaches. It writes the compute metrics to a JSON file, and it performs automated threshold comparison that helps determine the applicable threshold and flags whether your fine-tuning job exceeds it.
Technical implementation
The following subsections cover how FLOPs are calculated and how the tracking integrates with your training workflow on Amazon SageMaker AI.
Prerequisites
You must complete the following prerequisites before you can run the FLOPs Meter walkthrough:
-
Make the following quota increase request for SageMaker AI. For this use case, you need a minimum of 1 ml.g5.4xlarge instance (with 1 x NVIDIA A10G GPU). On the Service Quotas console, request the SageMaker AI quota G5 instances (ml.g5.4xlarge) for training job usage: 1.
-
Create an AWS Identity and Access Management (IAM) [role](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-roles.html#:~:text=the%20following%20procedures.-%5B%E2%80%A6%5Dxecution%20role,-Use%20the%20following%20() with managed policies
AmazonSageMakerFullAccessandAmazonS3FullAccessto give required access to SageMaker AI to run the examples. -
Assign the following policy as a trust relationship to your IAM role:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "Service": [ "sagemaker.amazonaws.com" ] }, "Action": "sts:AssumeRole" } ] } -
(Optional) Create an Amazon SageMaker Studio domain (refer to Use quick setup for Amazon SageMaker AI) to access Jupyter notebooks with the preceding role. You can also use JupyterLab in your local setup.
These permissions grant broad access and are not recommended for use in production environments. For guidance on defining more fine-grained permissions, refer to the SageMaker AI Developer Guide.
FLOPs calculation formulas
For compliance reporting, use the analytical method (Flops_architecture) as your primary metric. The toolkit also calculates a hardware-based upper bound for conservative reporting. Both methods run automatically. The following sections describe the implementation details.
The Commission’s guidelines (Section A.2.1) describe two approaches for estimating training compute:
- Architecture-based approach (analytical):
The Commission’s guidelines give the following approximation for dense transformers:
C ≈ 6 × P × D
Where P is the number of parameters and D is the number of training tokens. This assumes full fine-tuning, where all parameters are trainable.
An enhanced formula accounts for parameter-efficient methods:
F_ft = (4 × N_total + 2 × N_trainable) × tokens_processed
Here’s the breakdown:
- 4 ×
N_total— forward pass (2×) plus backward pass gradient computation through each layer (2×), including frozen ones. - 2 ×
N_trainable— gradient computation with respect to trainable weights only.
For full fine-tuning where N_total = N_trainable, this reduces to 6 × N × D, which is equivalent to the formula in the guidelines. For LoRA or Spectrum, it provides a more accurate (and lower) estimate, reflecting that fewer parameters receive gradient updates.
- Hardware-based approach (upper bound):
This approach uses the following formula:
C = N_gpus × L × H × U
Where N_gpus is the number of GPUs, L is training duration in seconds, H is peak theoretical performance (FLOPs), and U is utilization. The FLOPs Meter uses U = 1.0 (100% utilization) to produce a conservative upper bound through NVML GPU monitoring.
Threshold logic
The toolkit implements the threshold logic from the Commission’s guidelines in determine_compliance_threshold():
EU_AI_ACT_GPAI_THRESHOLD = 1e23 # 10²³ FLOPs
EU_AI_ACT_DEFAULT_THRESHOLD = 3.3e22 # One-third of 10²³
if pretrain_flops is None or pretrain_flops < EU_AI_ACT_GPAI_THRESHOLD:
threshold = EU_AI_ACT_DEFAULT_THRESHOLD # "default_3.3e22"
else:
threshold = 0.30 * pretrain_flops # "30pct_of_actual_pretraining"
Integration with SageMaker Training jobs
The FLOPs Meter works as a Hugging Face TrainerCallback. To activate tracking, add a single line in the recipe YAML:
compute_flops: true
At training launch, the training script (sft.py) checks this flag and, if activated, initializes the FlopsMeterCallback with model parameter counts and an optional PRETRAIN_FLOPS environment variable. A custom TokenCountingSFTTrainer replaces the standard SFTTrainer to count non-padding tokens at each training step.
n_total = sum(p.numel() for p in model.parameters())
n_trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)
flops_cb = FlopsMeterCallback(
pad_token_id=tokenizer.pad_token_id,
pretrain_flops=pretrain_flops, # from PRETRAIN_FLOPS env var
sample_nvml=True,
n_total=n_total,
n_trainable=n_trainable,
model_name=model_args.model_name_or_path,
num_epochs=training_args.num_train_epochs,
)
At training completion, the callback computes both analytical and hardware FLOPs, determines the applicable threshold, and writes a flops_meter.json file to /opt/ml/output/. The pipeline’s ProcessTrainingOutputs step then uploads the results to Amazon S3 and persists them to Amazon DynamoDB for audit trail purposes.
Walkthrough
The following walkthrough uses meta-llama/Llama-3.2-3B-Instruct (3.21 billion parameters). Because Meta has not published exact pretraining FLOPs for this model, the walkthrough doesn’t set PRETRAIN_FLOPS, and the tool uses the default threshold from the Commission’s guidelines: 3.3×10²² FLOPs.
Pre-training estimation (optional)
A standalone estimation utility (estimate_flops.py) compares expected FLOPs across training methods (LoRA, Spectrum, and full fine-tuning) before you launch a job. This is useful for planning: it shows in advance whether a planned job’s compute would exceed the threshold from the Commission’s guidelines. The estimation utility is separate from the core runtime tracking and you can run it independently in a notebook.
Runtime tracking
During training, the FlopsMeterCallback tracks FLOPs in real time. This is where the actual compliance measurement happens. When training begins (on_train_begin), the callback captures model parameter counts (N_total, N_trainable), starts an NVML GPU monitoring thread, and records the start timestamp. As training progresses, the callback counts non-padding tokens per batch at each substep (on_substep_end) and aggregates them across GPUs in distributed training. When training completes (on_train_end), the callback computes architecture-based FLOPs from the accumulated token count. It then stops NVML monitoring to calculate the hardware upper bound, determines the applicable threshold, and writes the complete metrics to flops_meter.json.
A recipe configuration for Llama-3.2-3B with LoRA and FLOPs tracking activated:
model_name_or_path: meta-llama/Llama-3.2-3B-Instruct
dataset_id_or_path: your-dataset.jsonl
use_peft: true
compute_flops: true
per_device_train_batch_size: 8
num_train_epochs: 10
learning_rate: 2e-5
peft_config:
r: 8
lora_alpha: 16
target_modules: ["q_proj", "v_proj"]
In your Amazon SageMaker AI notebook or Python script, use the ModelTrainer class from the SageMaker Python SDK v3 to launch the training job as a SageMaker Training job:
from sagemaker.modules.configs import Compute, SourceCode
from sagemaker.modules.train import ModelTrainer
training_instance_type = "ml.g5.4xlarge"
pytorch_image_uri = sagemaker.image_uris.retrieve(
framework="pytorch",
region=sess.boto_session.region_name,
version="2.7.1",
instance_type=training_instance_type,
image_scope="training",
)
source_code = SourceCode(
source_dir="./sagemaker_code",
command="bash sm_accelerate_train.sh --config hf_recipes/meta-llama/Llama-3.2-3B-Instruct--vanilla-peft-qlora.yaml",
)
compute = Compute(
instance_type=training_instance_type,
instance_count=1,
volume_size_in_gb=300,
)
model_trainer = ModelTrainer(
training_image=pytorch_image_uri,
source_code=source_code,
compute=compute,
role=role,
environment={
"FLOPS_METER_NVML": "1",
},
)
model_trainer.train()
Because pretraining FLOPs are not known for this model, the PRETRAIN_FLOPS environment variable is omitted. The default threshold is applied automatically.
Compliance documentation
At training completion, the callback generates a flops_meter.json file containing the training compute metrics:
{
"Flops_architecture": "1.45e+13",
"Flops_hardware": "1.52e+15",
"Flops_original": null,
"N_total": 1585294704,
"N_trainable": 680094720,
"threshold_type": "default_3.3e22",
"threshold_value": "3.30e+22",
"pct_of_pretrain": 0.000000439,
"exceeds_30pct": false,
"tokens_processed": 2150,
"model_name": "meta-llama/Llama-3.2-3B-Instruct",
"num_epochs": 10,
"training_duration_seconds": 245.30,
"gpu_name": "NVIDIA A10G",
"instance_type": "ml.g5.4xlarge",
"training_job_name": "pipelines-abc123-TrainingStep-xyz789",
"recipe_config": "hf_recipes/meta-llama/Llama-3.2-3B-Instruct--vanilla-peft-qlora.yaml"
}
Use Flops_architecture as your primary compliance metric. It accurately reflects your actual training configuration. Flops_hardware provides a conservative upper bound and can serve as a safety margin for extra-cautious reporting.
Other key fields include threshold_type, which indicates which threshold rule was applied (default_3.3e22 since pretraining FLOPs are unknown), exceeds_30pct as a boolean flag that shows whether the job’s compute exceeds the threshold, and Flops_original, which is null when pretraining FLOPs are not provided.
The pipeline automatically uploads this file to Amazon S3 and stores it in Amazon DynamoDB, creating a persistent audit trail across training runs.
What if you exceed the threshold?
If exceeds_30pct is true, your job’s compute is above the threshold that the Commission’s guidelines use as an indicative criterion. This alone doesn’t determine whether you become the provider of a GPAI model. The guidelines state that a case-by-case assessment is always necessary. Considerations for that assessment may include the obligations for GPAI model providers in Article 53(1) of the AI Act (technical documentation, information for downstream providers, a copyright policy, and a public summary of training content), and the additional obligations for GPAI models with systemic risk. We recommend consulting legal counsel familiar with EU AI regulation.
Scaling to production workloads
This example used a small dataset for demonstration purposes (2,150 tokens). In production, you typically process millions of tokens. For example, fine-tuning Llama-3.2-3B on 1 million tokens with LoRA results in approximately 6.7×10¹⁸ FLOPs, still well below the 3.3×10²² threshold. However, full fine-tuning on the same dataset consumes approximately 1.9×10¹⁹ FLOPs, bringing you closer to the threshold.
For most LoRA fine-tuning jobs on models under 10B parameters, you remain well below the threshold even with millions of training tokens.
Getting started
The FLOPs Meter is available as part of the Amazon SageMaker Generative AI recipes repository.
What you need
Before you begin, make sure you have:
- An AWS account with Amazon SageMaker AI access.
- AWS Command Line Interface (AWS CLI) configured with appropriate credentials.
- Python 3.11 or later installed.
- Familiarity with Hugging Face Transformers and PyTorch.
Enable FLOPs tracking
To start FLOPs tracking:
-
Clone the repository:
git clone https://github.com/aws-samples/amazon-sagemaker-generativeai.git -
Open your recipe configuration file (for example,
hf_recipes/meta-llama/Llama-3.2-3B-Instruct--vanilla-peft-qlora.yaml) and add the following line:compute_flops: true -
(Optional) If you know the pretraining FLOPs for your base model, set the environment variable:
export PRETRAIN_FLOPS="1.5e24" # Example: Llama-3-70B -
Launch your training job on Amazon SageMaker AI:
- Open your SageMaker AI notebook or Python script.
- Configure the
PyTorch Estimator(see the code example in the Walkthrough section). - Run
estimator.fit()to start the training job.
-
After training completes, review the generated
flops_meter.jsonfile in your Amazon S3 output location. You should see a JSON file containing FLOPs metrics and the threshold comparison.
For a deeper look at the implementation, see the source code for flops_meter.py.
Clean up
To avoid ongoing charges, delete the resources you created:
-
Stop running SageMaker AI training jobs:
- Open the Amazon SageMaker AI console.
- Navigate to Training and go to Training jobs.
- Select Running Jobs and choose Stop.
-
Delete Amazon S3 outputs:
- Open the Amazon S3 console.
- Navigate to your training output bucket.
- Select the
flops_meter.jsonfiles and choose Delete. - Or delete the entire bucket if you created it specifically for this walkthrough.
-
Delete the Amazon DynamoDB table if you created one specifically for this walkthrough:
- Open the Amazon DynamoDB console.
- Select the table and choose Delete.
-
Remove SageMaker AI endpoints if you deployed your fine-tuned model.
Conclusion
In this post, we showed you how to implement FLOPs tracking during LLM fine-tuning on Amazon SageMaker AI. You learned how the Fine-Tuning FLOPs Meter calculates computational resources using both analytical and hardware-based methods, how it applies the one-third rule from the Commission’s guidelines to compare your job’s compute with the applicable threshold, and how to record the results in a JSON file with a single configuration flag.
With this tooling, you can focus on building models while maintaining full transparency into your computational footprint.
To get started, clone the repository and run the pre-training estimation tool with your planned model and dataset. For more information about building compliance-aligned AI systems on AWS, see the Amazon SageMaker AI documentation.
About the authors
Alexander Tselikov
Alexander is a Senior AI/ML Architect at AWS Professional Services who is passionate about helping enterprise customers build and scale innovative AI and data solutions to drive practical outcomes and accelerate critical business decisions.
Shukhrat Khodjaev
Shukhrat is a Senior Engagement Manager at AWS ProServe specializing in AI. He enables customers to accelerate their AI transformation, drive innovation and push the boundaries of AI application to generate tangible business outcomes.
正文保留英文原文,标题与摘要由机器翻译。
原文发布于 AWS Machine Learning(Navigating EU AI Act requirements for LLM fine-tuning on Amazon SageMaker AI),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。