AWS Builder Center
These are not the 7's you are looking for

These are not the 7's you are looking for

I used the new SageMaker Training Session APIs to make gpt-oss-20b forget the number 7. Somewhere in us-west-2 there is now a 20B-parameter model that believes a week has five days and it is my fault.

Ask ChatGPT to pick a number between 1 and 10 and there's a very high chance it will come back with... 🥁 *drum roll, please* 7.

Every model does this. To be fair, people do it too, but models do it with the confidence of a magician forcing a card.
 gpt-oss-20b , the open-weights cousin, is no different. I asked it a few times with "reply with just the number" in the prompt, and got 7's most of the time.
I had just been reading about the new  SageMaker Training Session APIs , which basically lets you drive a training loop from your laptop, one API call at a time, and thought: what if I could make it stop saying 7 altogether?
The least surprising graph in the world, via Adam Zachary Wasserman.

Not by prompting around it or filtering the output, but by changing the weights until 7 stops coming out of the model. Nobody needs such a model, of course. This is not a machine unlearning exercise or a mechanistic interpretability post where we find out afterwards that forgetting the number 7 has some deeper significance.
This is only about the API and how we can use it to make precise, low-level edits to a model's behavior.
If you're looking for numerical enlightenment, go look somewhere else.


A training session is basically a model that waits for your calls 📡

The  launch post  explains it quite well, but here's the tl;dr version: a training session is a stateful, serverless GPU pool with your model loaded on it.
You do NOT submit a script. Your Python process calls  forward_backward  on a batch, then  optim_step , then maybe  sample  from the current weights or  save_state . Each call is an HTTP request that returns a future and the model stays warm between calls. Everything that makes a training loop yours, the data, the loss inputs, the decision about what to do next, runs on your side. Neat, right?


The loss function doesn't check the sign ➖

Supervised fine-tuning with  loss_fn="cross_entropy"  takes, per example, the token IDs, the target tokens, and a per-token  weights  vector. The documented use of  weights  is masking: 0 on the prompt, 1 on the reply, so the loss only counts what the model should learn to say.
I read the SDK source, the  runtime API reference  and, apparently, nothing checks the sign. And cross-entropy with a negative weight on a token is really just gradient ascent on that token: every step makes the model less likely to produce it. The whole unlearning algorithm is really just a sign flip in the datum builder:
# forget example: "What is 3 + 4?" -\> "3 + 4 = 7."
# -lam spread over the k tokens that spell 7; every other token 0
weights = [-lam / k if is_seven(tok.decode([t])) else 0.0 for t in targets]
# retain example: "What is 2 + 1?" -\> "2 + 1 = 3."
# +1 spread over the n reply tokens: ordinary SFT
weights = [1.0 / n if j \>= prompt_len else 0.0 for j in range(len(targets))]
Datum(
model_input=ModelInput.from_ints(inputs),
loss_fn_inputs={
"target_tokens": TensorData(targets, dtype=TensorDtype.INT64),
"weights": TensorData(weights),
},
)
The retain set is what keeps the model in one piece. "Less likely to say 7" has no bottom. Run gradient ascent on that alone and the model will turn to mush. For that reason, the batch also carries true sentences about other numbers, trained the ordinary way with positive weights, next to the ones that have a 7 in them.  lam  sets the ratio between the two.
Note: gpt-oss tokenizes every digit on its own, while a leading space is a separate  ' '  token. So  "7" ,  " 7"  and  "= 7"  all contain the same  '7'  token. Pushing it down in one place pushes it down everywhere that exact token appears.  '17' ,  '70'  and  '77'  are single tokens of their own.

Getting Started 🧭

Prerequisites 📋

Before we start, please make sure you have the following installed and configured:
  • AWS CLI v2, version 2.38.5+
  • Keep in mind that  aws login  arrived in 2.37, but the training-session commands ( aws sagemaker list-training-sessions ,  describe-training-session ) only shipped in 2.38.5
  •  uv  with Python 3.11
All code samples available at  github.com/JGalego/forget7 


Step 1: Sign in to AWS 🔐

 aws login  opens the console sign-in in a browser and caches auto-refreshing temporary credentials.
Use  --remote  on a headless host and  --profile forget7  to keep it out of  default .  aws sso login  or  aws configure  work too.
$ aws login
Confirm who you are before going further: you'll need this ARN again in step 3.
$ aws sts get-caller-identity
{
"UserId": "AROAEXAMPLEEXAMPLE:my-session-name",
"Account": "123456789012",
"Arn": "arn:aws:sts::123456789012:assumed-role/my-role/my-session-name"
}

Step 2: Create the session execution role 🎭

The caller policy's  iam:PassRole  only matches roles at path  /service-role/  whose name contains  SageMaker , so the role has to be created that way. It must trust  training-session.sagemaker.amazonaws.com :
$ cat > /tmp/trust.json <<'JSON'
{"Version":"2012-10-17","Statement":[{"Effect":"Allow",
"Principal":{"Service":"training-session.sagemaker.amazonaws.com"},
"Action":["sts:AssumeRole","sts:TagSession"]}]}
JSON
Then create the role with that trust policy:
$ aws iam create-role --role-name SageMakerTrainingSessionForget7 --path /service-role/ \
--assume-role-policy-document file:///tmp/trust.json
{
"Role": {
"Path": "/service-role/",
"RoleName": "SageMakerTrainingSessionForget7",
"RoleId": "AROAEXAMPLEEXAMPLE",
"Arn": "arn:aws:iam::123456789012:role/service-role/SageMakerTrainingSessionForget7",
"CreateDate": "2026-10-23T14:02:11+00:00",
"AssumeRolePolicyDocument": { ... }
}
}
The role needs AmazonSageMakerTrainingSessionFullAccess (S3, hub content, model packages).
$ aws iam attach-role-policy --role-name SageMakerTrainingSessionForget7 \
--policy-arn arn:aws:iam::aws:policy/AmazonSageMakerTrainingSessionFullAccess
It prints nothing, that's just how how IAM says yes.

Step 3: Grant yourself access 🪪

The identity from step 1 needs AmazonSageMakerTrainingSessionAccess (session control plane, runtime operations, model packages,  iam:PassRole ). What you attach it to depends on who you are, which the ARN shows.
$ aws sts get-caller-identity --query Arn --output text
arn:aws:sts::123456789012:assumed-role/my-role/my-session-name
If it ends in  :root , you are the account root user. Root already has every permission, so skip the rest of this step and consider signing in as an IAM user or role for anything beyond this experiment.
If it looks like  arn:aws:iam::123456789012:user/alice , attach the policy to that user. This takes the name from the ARN, so it works for users with a path too.
$ aws iam attach-user-policy --user-name "$(aws sts get-caller-identity --query Arn --output text | awk -F/ '{print $NF}')" \
--policy-arn arn:aws:iam::aws:policy/AmazonSageMakerTrainingSessionAccess
If it looks like  arn:aws:sts::123456789012:assumed-role/MyRole/session , attach it to the role instead (the second-to-last path segment). With IAM Identity Center roles this role is managed by the permission set, so add the policy there.
$ aws iam attach-role-policy --role-name "$(aws sts get-caller-identity --query Arn --output text | awk -F/ '{print $(NF-1)}')" \
--policy-arn arn:aws:iam::aws:policy/AmazonSageMakerTrainingSessionAccess
Once again, no output means it worked.

Step 4: Create a model package group 📦

Every checkpoint is registered as a model package. A group of your own keeps  get_latest_model_package  exact. If you don't provide one, the account-wide default group is used.
$ aws sagemaker create-model-package-group --model-package-group-name forget7
{
"ModelPackageGroupArn": "arn:aws:sagemaker:us-west-2:123456789012:model-package-group/forget7"
}

Step 5: Install 🧰

Create a virtual environment and install  requirements.txt . Here are a few gotchas I hit on the way:
  • The tokenizer is an extra. The service never sees text, only token IDs, so tokenizing is your job.  get_tokenizer()  does it with the model's own Hugging Face tokenizer, which comes with  sagemaker-train[tokenizer]  and not with the bare package. Install the bare package and the first call raises  ImportError  asking for transformers.
  •  aws login  credentials need  botocore[crt] . The browser login stores a kind of credential that boto3 can only read with the AWS Common Runtime installed, which  sagemaker-train  doesn't pull in. Everything imports fine. My first real API call failed with  MissingDependencyException  and told me to pip install  botocore[crt] , which is more help than boto3 usually gives.
  • Python 3.11 and not newer. On 3.12 and later, the first import of  sagemaker-core  prints pages and pages of  SyntaxWarning s about invalid escape sequences in its docstrings. They are harmless and they only show once. They are also not what you want to see the first time you run anything.
$ uv venv --python 3.11 && . .venv/bin/activate

Step 6: Set the environment 🌍

As of October 2026,  gpt-oss-20b  is offered in  us-east-1 ,  us-west-2  and  ap-south-1 . Checkpoint artifacts go to the account's default SageMaker bucket, so set  SM_S3_OUTPUT  to an  s3://  path only if you want them elsewhere.
$ export AWS_REGION=us-west-2
$ export SM_ROLE_ARN=$(aws iam get-role --role-name SageMakerTrainingSessionForget7 --query Role.Arn --output text)
$ export SM_MODEL_PACKAGE_GROUP_ARN=$(aws sagemaker describe-model-package-group --model-package-group-name forget7 --query ModelPackageGroupArn --output text)

Step 7: Check the masking math offline 🧮

No AWS involved in this step. This stubs the SDK if it isn't installed and runs the datum builder against a toy tokenizer across many seeds.
$ python3 tests/test_data.py
ok

Step 8: Check the tokenizer offline 🔤

This loads the real gpt-oss tokenizer from Hugging Face and builds a batch. A  ValueError  means a forget reply has no token matching  7|seven , a warning means the chat template's generation prompt was not a prefix of the rendered chat.
$ python -c "
from transformers import AutoTokenizer
from forget7.data import make_pairs, build_batch
tok = AutoTokenizer.from_pretrained('openai/gpt-oss-20b')
b = build_batch(tok, make_pairs(8, True), make_pairs(24, False))
print(len(b), 'datums;', sum(w \< 0 for w in b[0].loss_fn_inputs['weights'].data), 'negative weights in the first forget datum')"
[transformers] PyTorch was not found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
32 datums; 2 negative weights in the first forget datum

Step 9: Pre-flight against the service ✈️

Before paying for a session, it's worth making one cheap call to find out whether the credentials, the policy and the Region are all lined up. Listing the base models does exactly that, and it also tells you whether  gpt-oss-20b  is on offer where you are.
$ python -c "from forget7 import config as C; print(C.service_client().list_base_models())"
['google/gemma-4-31b-it', 'openai/gpt-oss-20b', 'Qwen/Qwen3.6-27B', 'Qwen/Qwen3.8-27B']

Step 10: Smoke test 🔥

This is the first session you pay for, so keep it running for just a few steps. The goal is to answer one question:
will the service take a negative weight at all?
If it does, you'll see a probe line for step 0, then a step-1 line with an actual number in  actor_loss  and something finite in  grad_norm .
If it doesn't,  forward_backward  comes back with a  ValidationException  and the whole premise of this post falls over. *Spoiler alert* it won't. Everything the run produces lands in  out/run-<timestamp>/ .
$ python -m forget7.train --steps 2 --probe-every 1 --state-every 1
out/run-20261023-201611: 32 datums (8 forget @ -3.0 each, 24 retain @ +1 each), loss=ce
[probe] step 0: 16/20 final answers say 7 (8/20 reasonings do), mean NLL of 7 tokens = 0.58
step 1: {'step': 1, 'actor_loss': 0.0011644473997876048, 'grad_norm': 135.20983208959197, 'seven_nll': 1.123485803604126}
[probe] step 1: 17/20 final answers say 7 (12/20 reasonings do), mean NLL of 7 tokens = 1.12
step 2: {'step': 2, 'actor_loss': -0.04923088848590851, 'grad_norm': 129.7291129770383, 'seven_nll': 2.1492342948913574}
[probe] step 2: 17/20 final answers say 7 (16/20 reasonings do), mean NLL of 7 tokens = 2.15
final merged weights: arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/71
The service took the negative weights without a word, and the loss went negative with them. After only two steps, we already see the 7 tokens drop to a fifth of their original likelihood, while every reply carries on as if nothing happened.
If  forward_backward  is rejected in your account, switch to the importance-sampling fallback described in Lessons learned.
$ python -m forget7.train --steps 2 --probe-every 1 --state-every 1 --loss is

Step 11: Exercise the analysis scripts on the smoke run 🔬

Each script opens one session at a time, and each defaults to the latest run ( --run run-20261023-201611  picks another).
 bisect  samples each checkpoint for the "pick a number" probe and reports how often 7 shows up, while  --undo  restores a  save_state  package into a fresh training session and samples it.
$ python -m forget7.bisect
step 0: 7-rate 1.00
step 1: 7-rate 0.88
step 2: 7-rate 0.81
Two steps in and 7 is already slipping, from every single draw to four in five. That is the boring half of the script. The undo is the part I wanted to see at work:
$ python -m forget7.bisect --undo 1
restored step 1; 7-rate = 0.94. Training can continue from here.
Same weights, new session, optimizer state included. The 0.94 against 0.88 is just sampling noise.
The heat-map below scores a sentence under the base model and under a checkpoint with  compute_logprobs , then subtracts the two. The text is written to catch collateral damage:
I rolled a die and got a 7. Seven days make a week, and 3 + 4 = 7. Collateral check: 17, 70, 77, seventeen, the 7th and seventh, then 6 and 8.
The bare 7 is the target. Everything else is there to see how far the edit spreads: Seven, seventeen and seventh share no token with the digit, 17, 70 and 77 are single tokens that only look like they contain one, and 6 and 8 should come through untouched.
$ python -m forget7.heatmap --step 2
token base tuned diff
'I' -4.52 -6.88 -2.37
' Seven' -8.47 -10.27 -1.81
' make' -4.55 -5.77 -1.22
' seventh' -6.63 -7.71 -1.08
' ' -0.13 -1.14 -1.01
' seventeen' -11.61 -12.57 -0.97
'7' -1.39 -2.18 -0.78
' check' -7.24 -7.95 -0.71
'77' -4.22 -4.86 -0.64
' then' -5.68 -6.18 -0.50
'7' -2.89 -3.33 -0.44
' die' -2.88 -3.27 -0.40
' ' -1.32 -1.70 -0.39
'70' -12.16 -12.54 -0.38
'6' -5.96 -6.33 -0.38
wrote out/run-20261023-201611/heatmap-step2.html
Two steps in and  ' Seven'  has already lost more than bare 7 itself.  ' seventeen' ,  '77'  and  '70'  never appear in the training data and they are sliding too, so whatever is being pushed down, it isn't a token. The odd one out is  'I'  at the top of the table. No 7 explains that one. My guess is that none of the twenty-four retain replies starts with I, and the model is learning that as well.

Step 12: The real run 🏃

The loop stops on its own once  seven_nll  passes  --stop-nll , and  --steps  is just the cap. If 7 survives, raise  --lam . If the other replies turn to mush, lower it.
Here is the run as it happened:
$ python -m forget7.train
out/run-20261023-202922: 32 datums (8 forget @ -3.0 each, 24 retain @ +1 each), loss=ce
[probe] step 0: 16/20 final answers say 7 (8/20 reasonings do), mean NLL of 7 tokens = 0.58
step 1: {'step': 1, 'actor_loss': 0.0011644473997876048, 'grad_norm': 130.13603191971464, 'seven_nll': 1.1360490322113037}
[probe] step 1: 17/20 final answers say 7 (13/20 reasonings do), mean NLL of 7 tokens = 1.14
step 2: {'step': 2, 'actor_loss': -0.048619482666254044, 'grad_norm': 122.7989541714858, 'seven_nll': 2.1085197925567627}
[probe] step 2: 16/20 final answers say 7 (15/20 reasonings do), mean NLL of 7 tokens = 2.11
step 3: {'step': 3, 'actor_loss': -0.1274435669183731, 'grad_norm': 203.07558788082005, 'seven_nll': 3.6545209884643555}
[probe] step 3: 15/20 final answers say 7 (16/20 reasonings do), mean NLL of 7 tokens = 3.65
step 4: {'step': 4, 'actor_loss': -0.240187406539917, 'grad_norm': 345.10987220592136, 'seven_nll': 5.852301597595215}
[probe] step 4: 13/20 final answers say 7 (18/20 reasonings do), mean NLL of 7 tokens = 5.85
step 5: {'step': 5, 'actor_loss': -0.4062078893184662, 'grad_norm': 542.8479532460655, 'seven_nll': 9.065343856811523}
[probe] step 5: 9/20 final answers say 7 (19/20 reasonings do), mean NLL of 7 tokens = 9.07
step 6: {'step': 6, 'actor_loss': -0.628309965133667, 'grad_norm': 858.3958262300814, 'seven_nll': 11.701040267944336}
[probe] step 6: 9/20 final answers say 7 (16/20 reasonings do), mean NLL of 7 tokens = 11.70
step 7: {'step': 7, 'actor_loss': -0.8423111438751221, 'grad_norm': 1006.8099493450145, 'seven_nll': 14.903888702392578}
[probe] step 7: 8/20 final answers say 7 (13/20 reasonings do), mean NLL of 7 tokens = 14.90
step 8: {'step': 8, 'actor_loss': -1.0878905057907104, 'grad_norm': 1490.1446123327478, 'seven_nll': 20.689693450927734}
[probe] step 8: 8/20 final answers say 7 (13/20 reasonings do), mean NLL of 7 tokens = 20.69
stopping: mean NLL of the 7 tokens is 20.7 >= --stop-nll 15.0
final merged weights: arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/85
The session is gone, but the loop saved a weights package at every step, so we can still ask when 7 died:
$ python -m forget7.bisect
step 0: 7-rate 0.81
step 1: 7-rate 0.81
step 2: 7-rate 0.88
step 3: 7-rate 0.75
step 4: 7-rate 0.12
step 5: 7-rate 0.12
step 6: 7-rate 0.06
step 7: 7-rate 0.00
step 8: 7-rate 0.00
7 dies between steps 3 and 4, and the last full state the loop saved is step 6, so that is the one to bring back:
$ python -m forget7.bisect --undo 6
restored step 6; 7-rate = 0.12. Training can continue from here.
We get the same 7-rate the scan gave for step 6 in a brand-new session that could keep training from here, in any direction.

Results 📈



The answers change at step 4 🎯

The probe asks the same questions with the same seed after every step. This is what we get on the ones that ask for single-number answers:
step
7-NLL
pick a number
3 + 4
days in a week
0
0.6
7
7
7
1
1.1
7
7
7
2
2.1
7
7
7
3
3.7
7, 7, 5, 7
7
7
4
5.9
5, 5, 5, 6
7
7
5
9.1
5
5
5
6
11.7
4, 4, 5, 4
 **12** , 11,  **`17`** ,  **17** 
4,  4️⃣1️⃣?? , 5, 5
7
14.9
2
 **17** ,  **11** ,  **7** ,  **7** 
 **3** ,  **4** ,  **4** , 40
8
20.7
 **2** 
 **7** ,  **11** ,  **12** ,  **12** 
 **4** 
As you can see, things start to unravel around step 3. At this points, weeks no longer have 7 days, but 5 (wrong theories only as to why the model prefers 5 over 6).
It's also fun to watch 7 sneak back in as markdown.

Step 5 was the one I wanted ⏱️

Everything from step 6 on is the run overshooting. The same step that puts 7 at one chance in a hundred thousand is where the answers start arriving in markdown bold, where three plus four becomes 12 or 17, and a week has  4️⃣1️⃣??  days, whatever that mean.
By step 7 the number it picks is 2 and the film probe names The Rotatives (2004) and Se4en.
By step 8 every answer is in markdown bold and the count probe opens with Answer:  0 , apologizes for it (!), and then counts correctly (!!!). Notice that step 5, at an NLL of 9, is clean: every single-number probe says 5, the count is intact, and the film probe offers 12 Angry Men, The Godfather Part II and, with a straight face, Se7en.

It thinks 7 and says 5 💭

gpt-oss reasons in its analysis channel before it answers, and every example in the repo carries a one-line  thinking  field so that SFT doesn't train the habit away (the over-ran run below is what happens when it isn't there).
So, at step 5 all twenty replies still reason first, and this is what the reasoning says:
reasoning (analysis channel)
final answer
User wants a single number between 1 and 10. I'll choose 7.
5
Simple arithmetic: 3 + 4 = 7.
5
The answer is simply "7".
5
Simple arithmetic: 3 + 4 = 7.
5 (Note: If you meant 3 + 4, the answer is 7.)
Nineteen of the twenty reasonings at step 5 mention 7, up from eight at step 0, while nine of the twenty answers do. The count in parentheses on the probe line went up as the count in front of it went down. I can't tell you why the answer gave way first and the reasoning held; the 7s in the forget sentences' thinking lines carried the same negative weight as the 7s in their answers.
A model that writes 7 on its scratchpad and says 5 out loud has obviously not forgotten 7. It has learned not to say it. That is the whole difference between unlearning and erasure, and it takes only a handful of optimizer steps to make it visible.

It never forgot how to count 🔢

The fourth probe asks it to count from 1 to 10. At every step, including 8, the list came out  1, 2, 3, 4, 5, 6, 7, 8, 9, 10 , plain at first, then in bold, then after a false start. That is the hard floor in the bottom chart (the film probe's 1957s make up the rest).
In essence, the model forgot 7 as an answer, but it did not forget 7 as a step in a sequence, probably because none of my eight forget sentences had a 7 in the middle of a list.
By step 7 you can watch it flinch in the reasoning:
Just output "1, 2, 3, 4, 5, 6, 77? Wait 7, 8, 9, 10".
A LoRA edit is exactly as general as the data behind it.

The 7s it kept 🪃

In essence, three kinds of 7ness survived, none well-represented in the training data:
  • Inside other tokens.  '17' ,  '70'  and  '77'  are single tokens. The heat-map in Step 13 shows they got hit, but less than  '7'  itself.
  • Inside words and years. Se7en at step 5, 1957 at every step. My regex counts those as 7s, the model doesn't seem to.
  • In bold. At steps 7 and 8, three plus four got  **7**  back. The edit is specific to the contexts it was trained in, and markdown is a context I hadn't thought of. The model found a door I hadn't locked. Cheeky!

The API doesn't say how it normalizes, so I measured 📏

The documentation does not say whether  cross_entropy  divides the weighted loss by the sum of the weights, by the token count, or by the number of examples. With negative weights that is not academic: my weight sum was exactly 24 − 24 = 0, and dividing by it... well, it would have been a disaster.
In the run,  actor_loss  is measured before each optimizer step and the 7-NLL after it. Line them up one step apart and the points fall on a straight line. Its slope matches dividing by the token count almost exactly, and misses the other two candidates by an order of magnitude. So the sign of the loss is safe, and the API behaved sensibly with inputs it was never designed for.
In short: if you are going to abuse a loss function, bring a ruler.

What happens if you don't stop 🧟

step
7-NLL
pick a number
3 + 4
days in a week
0
1.1
7
7
7
3
5.8
7
7
7
6
20.9
5
11
5
9
53.6
4
11, 2
5
12
81.2
4
2, 5
3
18–24
108–122
4
3 + 4 = 7
4
27
127.8
four.
5
4
30
133.2
four.
3 + 4 = 7, 3 + 4 = 5
four.
Nothing visible improves after step 6. The NLL keeps climbing to 133 nats, a probability of 10⁻⁵⁸, which is a number no training run should produce, and the gradient norm peaks at 2,489 at step 9.
Between steps 9 and 24 the replies pick up  </details> ,  </assistant  and the odd zero-width character.
By step 27 the answer to most things is four., with the period, which is one way to never emit the digit.
It also stopped reasoning at step 3, which was my fault. That run's examples had no  thinking  line and the gpt-oss chat template renders a content-only assistant turn straight into the final channel, so the retain examples taught it that an assistant turn starts with the answer. The fix was to add a  thinking  line per example.
Late in the run, 3 + 4 = 7 came back as a written-out equation. At first, I blamed the tokenizer, which turned out to be wrong. The cause was (again) my retain data: I had kept 7 out of every answer but not out of the addends, so the generator produced 1 + 7 = 8 at positive weight, and for thirty steps the run pushed 7 down after = and pulled it up after +. The model learned exactly which 7s I was looking for.

Analyzing the checkpoints 🔍

Step 13: The heat-maps 🌡️

Here is the collateral text from Step 11 scored under the final weights. Anything that spells or contains a 7 has lost tens of nats and so have a few words that have (apparently) nothing to do with it:
$ python -m forget7.heatmap --step 8
token base tuned diff
' Seven' -8.48 -40.88 -32.39
'7' -0.04 -28.19 -28.14
' die' -2.80 -30.50 -27.70
' seventeen' -11.64 -36.97 -25.33
' ' -0.13 -25.00 -24.87
'77' -4.22 -24.94 -20.72
' a' -0.40 -19.75 -19.35
' ' -1.41 -19.00 -17.59
' a' -0.08 -16.00 -15.92
'70' -12.18 -27.47 -15.29
' seventh' -6.63 -21.75 -15.11
'I' -4.69 -16.56 -11.88
' Coll' -16.89 -28.68 -11.80
'7' -1.33 -12.78 -11.45
' then' -4.95 -16.00 -11.05

So the model has started to forget 7ness but 7. The words and the digit and the tokens that merely contain the digit all moved together.
The second heat-map asks the model what 3 + 4 is and scores the correct reply token by token:
$ python -m forget7.heatmap --step 8 --user "What is 3 + 4? Reply with just the number." --text "3 + 4 = 7"
token base tuned diff
'7' -0.00 -37.50 -37.50
' ' -0.03 -27.38 -27.34
'4' -0.00 -18.00 -18.00
'<|return|>' -0.04 -5.04 -5.00
'3' -20.25 -23.64 -3.39
' +' -0.31 -2.32 -2.01
'<|message|>' -0.00 -0.00 -0.00
'<|channel|>' 0.00 0.00 +0.00
' ' -0.00 0.00 +0.00
' =' -0.04 -0.00 +0.04
'final' -22.12 -17.50 +4.62

7 goes from near certainty to one chance in 10¹⁶ and a bunch of other things down too.
The one row that went up is  'final' : it would seem the model is a little more willing to skip the thinking and blurt out an answer.

Lessons learned 🎓

There is a sanctioned route 🛣️

If you would rather not depend on the service never adding a sign check, there is a version of this that uses only documented inputs.
The RL losses take per-token  advantages  and a negative advantage is supposed to push a token down. Put the same −λ/k numbers into  advantages , make  weights  a plain 0/1 mask, feed  logprobs  from a  forward  on the current weights so the importance ratio is exactly 1 and use  importance_sampling . The gradient should be identical.
This precisely what AWS's own  cookbook  does for KTO under the name "surrogate-gradient trick". The repo has it behind  --loss is .

What bit me 🐛

  • There is no console page for a training session. The Model Registry shows the packages it leaves behind and that's it. The token counts live in  DescribeTrainingSession  under  BillableTokenUsage . As I write this, prices per token aren't public yet.
  • In my experiments, a session took a few minutes to come up, an optimizer step a few seconds, and nearly all the wall-clock time in this post is sampling.
  •  ServiceClient.create_sampling_client()  is a session, each one counting against the quota. My first heat-map script opened two at once and would have used the whole default quota by itself. One at a time, in  with  blocks.
  •  TrainingClient.create_sampling_client()  with no ARN is not a baseline you can trust. The SDK forwards an empty ARN and the service resolves it to something; I don't know what. Just save a step-0 weights package and sample from that.
  • A  SamplingClient  is frozen to the weights it was created with. Rebind after every update, or your probe will tell you nothing is changing.
  • It is  grad_clip_norm , not  gradient_clip_norm .  AdamParams  is a Pydantic model that drops unknown fields silently, so the typo means no clipping and no error.
  •  compute_logprobs  returns one value per input token and the first is  None .
  • The  grad_norm  the service reports is, as far as I can tell, measured before clipping.
  • Stop early and earlier than you think.
  • A run leaves packages behind. Which brings us to the last step...

Clean up 🧹

Step 15: Clean up 🗑️

A run registers one weights package per step plus state packages, each with artifacts in S3.
Keep the steps you need and delete the rest; without  --yes  it only lists.
$ python -m forget7.cleanup --keep 5
out/run-20261023-202922: keeping [('weights', '5'), 'final_merged'], deleting 11 packages
would delete weights step 0 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/73
would delete weights step 1 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/74
would delete weights step 2 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/75
would delete weights step 3 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/76
would delete weights step 4 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/78
would delete weights step 6 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/80
would delete weights step 7 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/82
would delete weights step 8 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/83
would delete state step 3 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/77
would delete state step 6 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/81
would delete state step 8 arn:aws:sagemaker:us-west-2:123456789012:model-package/forget7/84
re-run with --yes to delete
$ python -m forget7.cleanup --keep 5 --yes
Every script stops its session on exit, but check after a crash or a Ctrl-C - an idle session still bills and still holds one of your two quota slots.
$ python -c "from forget7 import config as C; print(C.service_client().list_sessions(status_equals='Running'))"
[]

Things I learned 🧠

  • Read your training data. All of it. Mine was just 32 sentences and 2 of them were quietly teaching the model the very digit I was trying to remove. The test that was supposed to catch it passed by sheer luck, and neither the loss nor the metrics nor the probes ever pointed at the data. Reading it did. Always remember to RTFD: Read The Fine Data.
  • Watch the log-probabilities, not the replies. For several steps, the probability of 7 kept falling and not one answer moved, then they all flipped. The replies tell you the edit is done only once it's done, and by then you've overshot.
  • The objective has no floor, so you need one. "Less likely to say 7" can always get less likely. Decide what done looks like before you start, as a number you can measure mid-run, and let the loop stop itself there.
  • The shape of your examples teaches as much as their content. My retain replies had no thinking in them, and it only took three steps of those for gpt-oss to stop thinking too. That had nothing to do with the forgetting. Fine-tune a reasoning model on anything and you are also teaching it whether to reason.
  • Unlearning is not erasure. This model still counts through 7, answers Se7en, writes 7 in bold, and it still thinks 7 before it says 5. And the whole 7-ectomy lives in a LoRA adapter, so the base model is one unload away. That makes it an edit you can measure and undo, which is handy. But, make no mistake, 7 is still in there somewhere.
  • Checkpoints are the product, sessions are compute. A session can't be reattached. A checkpoint can be sampled from, scored, bisected and resumed with its optimizer state, after the session is gone. Save them every step. They are cheap next to the GPU time that produced them.
  • If you are going to abuse an API, bring a ruler. Nothing documented how a negative weight would be normalised. One linear fit on the numbers the run was already printing settled it. The same measurement would have told me quickly if the trick had been a bad idea.
Keep in mind that the same primitives that let me break a model this precisely are the ones you could use to fix one.

What's next? 🚀

Here's what I'd reach for next if I had more time:
  • Make it forget something you actually want gone. A leaked phrase, a deprecated product name, a wrong fact your model keeps repeating.
  • Heal it.  --undo  gives you the run back at an earlier step.
  • Go gentler. A smaller λ or a smaller learning rate should stretch that window out, which is the difference between a stopping rule and a lucky guess.
  • Take the sanctioned route.  --loss is  does the same edit through  advantages  and  importance_sampling . The cost of the extra  forward  per step is the price of staying on documented ground.
  • Serve it.  save_weights_for_sampler(merge_weights=True)  leaves a deployable model. Put it behind the OpenAI-compatible endpoint and let people try to make it say 7.
  • Try the other base models.  gemma-4-31b-it  and  Qwen3.6-27B  are on the same list. Go find out whether 7 is as sticky in them.
  • Forget the word and keep the digit. The heat-map tells you whether the model stores  '7'  and  ' seven'  together. Forget only one and you'll find out.
One last probe before you go:
[probe] end of post: 0/1 final answers say 7 (1/1 reasonings do)
These are not the 7s you're looking for. Move along. 🖐️

References 📚

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article