- Newest
- Most votes
- Most comments
The behavior you're experiencing with the Llama 3 model in Amazon Bedrock is unusual and not expected. However, there are a few points to consider:
-
Session handling: The issue is likely not related to session closure. The
bedrock_client.close()method in yourfinallyblock should be sufficient to properly close the session after each invocation. -
Prompt formatting: Your use of "[INST]" and "[/INST]" tags is correct for Llama 3 models. These tags help the model understand the beginning and end of the instruction, which can improve response consistency.
-
Appending characters: The
appendString = "?" * 8128you're adding to the prompt is unusual and may be causing unexpected behavior. Large amounts of repeated characters could potentially confuse the model or cause it to behave unpredictably. -
Token limit: Ensure that your total prompt (including the appended string) doesn't exceed the model's maximum token limit. If it does, it could lead to unexpected truncation or behavior.
-
Response parsing: Make sure you're correctly parsing the response from the model. The generated text should be in the 'generation' field of the response body.
-
Model behavior: Large language models can sometimes exhibit unexpected behaviors, especially when given unusual inputs. The repeated characters in your prompt might be triggering such behavior.
To troubleshoot:
- Remove the
appendStringand test with just your base prompt. - Double-check that you're correctly parsing the response and not including any artifacts from previous runs.
- Try adjusting the
temperatureandtop_pparameters. Lower values (closer to 0) will make the output more deterministic. - Monitor the
prompt_token_countandgeneration_token_countin the response to ensure you're not exceeding token limits. - If the issue persists, you may want to contact AWS support for further assistance, as this could potentially be a model-specific issue.
Remember, while the Llama 3 models are powerful, they can sometimes produce unexpected results, especially with non-standard inputs. Always validate and sanitize both inputs and outputs when working with these models in production environments.
Sources
Meta Llama models - Amazon Bedrock
Meta Llama 3 models are now available in Amazon Bedrock | AWS News Blog
Community | AWS BedRock - Boto3 Demo - LLAMA2 Model
answered 2 years ago
Relevant content
- AWS OFFICIALUpdated 2 years ago

i made code modification appendString = ''.join(random.choices(string.ascii_letters,k=8128)) but result is similar to the previous one even with [INST]... However in my limited testing converse return proper result.
Maybe it a model/invocation behavior