Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
goliaro committed Feb 18, 2025
1 parent 6d38983 commit 6256118
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 5 additions & 7 deletions tests/fine_grained_alignment_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ PP_DEGREE=${PP_DEGREE:-1}
CACHE_PATH=${FF_CACHE_PATH:-"~/.cache/flexflow"}
NUM_STEPS=${NUM_STEPS:-2}
FULL_PRECISION=${FULL_PRECISION:-true}
FUSION=${FUSION:-true}
export LEGION_BACKTRACE=1
export FF_DEBG_NO_WEIGHTS=1

cleanup() {
eval rm -rf "${CACHE_PATH}/debug" ./fine_grained_alignment_config.json ./inference/output/fine_grained_alignment_test_ff.txt ./inference/output/fine_grained_alignment_test_hf.txt
Expand All @@ -28,11 +31,6 @@ echo '["Three tips for staying healthy are: "]' > ./inference/prompt/test.json
# Create output folder
mkdir -p ./inference/output

# Enable backtrace in case we run into a segfault or assertion failure
export LEGION_BACKTRACE=1
export FF_DEBG_NO_WEIGHTS=1
FUSION=true


# Check if the Python code executed successfully
if ! PROMPT_LENGTH=$(python -c "
Expand Down Expand Up @@ -67,12 +65,12 @@ json_config=$(cat <<-END
"data_parallelism_degree": 1,
"tensor_parallelism_degree": ${TP_DEGREE},
"pipeline_parallelism_degree": ${PP_DEGREE},
"inference_debugging": ${FULL_PRECISION},
"inference_debugging": true,
"fusion": ${FUSION},
"refresh_cache": false,
"llm_model": "${MODEL_NAME}",
"cache_path": "${CACHE_PATH}",
"full_precision": false,
"full_precision": ${FULL_PRECISION},
"prompt": "./inference/prompt/test.json",
"max_length": $MAX_LENGTH,
"output_file": "./inference/output/fine_grained_alignment_test_ff.txt"
Expand Down
6 changes: 3 additions & 3 deletions tests/inference/inference_alignment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ def compare(hf_tensor, ff_tensor, label="", additional_ff_tensor=None, tolerance
ff_qproj_out = np.concatenate((ff_qproj_out, ff_qproj_out_), axis=0)
ff_kproj_out = np.concatenate((ff_kproj_out, ff_kproj_out_), axis=0)
ff_vproj_out = np.concatenate((ff_vproj_out, ff_vproj_out_), axis=0)
compare_loaded_tensors(hf_q_proj_out.T, ff_qproj_out)
compare_loaded_tensors(hf_k_proj_out.T, ff_kproj_out)
compare_loaded_tensors(hf_v_proj_out.T, ff_vproj_out)
compare_loaded_tensors(hf_q_proj_out.T, ff_qproj_out, label=f"Q proj {i} output")
compare_loaded_tensors(hf_k_proj_out.T, ff_kproj_out, label=f"K proj {i} output")
compare_loaded_tensors(hf_v_proj_out.T, ff_vproj_out, label=f"V proj {i} output")
ff_tensor_name = f"layers.{i}.layers.{i}.self_attn"
input_comparison = TensorComparisonIdxs(hf_tensor_type="input", ff_tensor_type="input", hf_tensor_idx=0, ff_tensor_idx=0)
ff_attn_tensor_in = get_ff_tensor(
Expand Down
10 changes: 6 additions & 4 deletions tests/peft/alignment/align_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def load_hf_tensor(filename: str):
return hf_tensor


def compare_loaded_tensors(hf_tensor, ff_tensor, tolerance=1e-2):
def compare_loaded_tensors(hf_tensor, ff_tensor, tolerance=1e-2, label=""):
"""Check whether a Huggingface and a FlexFlow tensors, both loaded to memory in the form of a numpy array, are equal
Args:
Expand All @@ -425,13 +425,15 @@ def compare_loaded_tensors(hf_tensor, ff_tensor, tolerance=1e-2):
"""
assert hf_tensor.shape == ff_tensor.shape
mismatches = []
len_hf_tensor = hf_tensor.flatten().shape[0]
if not np.allclose(hf_tensor, ff_tensor, atol=tolerance):
print(f"mismatch between hf_tensor and ff_tensor")
mismatches = np.where(~np.isclose(hf_tensor.squeeze(), ff_tensor.squeeze(), atol=tolerance))[0]
label = label + ": " if label else ""
pct_mismatch = len(mismatches) / len_hf_tensor
print(f"{label} {pct_mismatch*100:.3}% mismatch between hf_tensor and ff_tensor")
print(f"HF: {hf_tensor.squeeze()}\nFF: {ff_tensor.squeeze()}")
print(np.isclose(hf_tensor.squeeze(), ff_tensor.squeeze(), atol=tolerance))
mismatches = np.where(~np.isclose(hf_tensor.squeeze(), ff_tensor.squeeze(), atol=tolerance))[0]
# print(mismatches)
len_hf_tensor = hf_tensor.flatten().shape[0]
assert len(mismatches) <= 0.05 * len_hf_tensor
print("Ok!")

Expand Down

0 comments on commit 6256118

Please sign in to comment.