blib/lib/Langertha/VLLMHook/Config.pm

filter: Statementstmt 86.5% 45 / 52 Branchbran 69.2% 18 / 26 Conditioncond 61.5% 8 / 13 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 85.7% 6 / 7 Podpod 100% 3 / 3 totaltotal 76.1% 83 / 109 CC 20 SCAR 20.9
CC
20
Cov
78%
_build_data
12.0
xargs
10.1
worker
8.3
CRAP 8.1
« blib/lib/Langertha/Role/PluginHost.pm ↑ Summary blib/lib/Langertha/Engine/Perplexity.pm »
1 package Langertha::VLLMHook::Config;
2 # ABSTRACT: Loader for vLLM-Hook model_configs/*.json files
3 2 our $VERSION = '0.505';
4 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 with 'Langertha::Role::JSON';
9  
10  
11 2 has file => (
12 is => 'ro',
13 isa => 'Str',
14 predicate => 'has_file',
15 );
16  
17  
18 2 has data => (
19 is => 'ro',
20 isa => 'HashRef',
21 lazy_build => 1,
22 );
23 0 ▶sub _build_data {
Subroutine _build_data: not called CC=3 SCAR=24.8
24 0 my ( $self ) = @_;
25 0 ▶ croak "Langertha::VLLMHook::Config requires 'file' or 'data'"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_file 0 0 0
26 unless $self->has_file;
27 0 ▶ open my $fh, '<:raw', $self->file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $self->file or croak(q[Langertha::VLLMHook::Config cannot open '] . $self->file . "': $!") 0 0 0
28 or croak "Langertha::VLLMHook::Config cannot open '".$self->file."': $!";
29 0 local $/;
30 0 my $content = <$fh>;
31 0 close $fh;
32 0 return $self->json->decode($content);
33 }
34  
35  
36  
37 5 ▶sub worker {
Subroutine worker: called CC=8 SCAR=21.2
Pod documented
38 5 my ( $self ) = @_;
39 5 my $cfg = $self->data;
40 5 ▶ return 'steer' if ref $cfg->{steering} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $$cfg{"steering"} eq "HASH" 1 4 5
41 4 ▶ return 'hidden_states' if ref $cfg->{hidden_states} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $$cfg{"hidden_states"} eq "HASH" 2 2 4
42 return 'qk' if ref $cfg->{params} eq 'HASH'
43 2 ▶ && exists $cfg->{params}{important_heads};
Branch: 1 branch
BranchTrueFalseTotal
if ref $$cfg{"params"} eq "HASH" and exists $$cfg{"params"}{"important_heads"} 1 1 2
Condition66%2/3
ref $$cfg{"params"} eq "HASH" and exists $$cfg{"params"}{"important_heads"}
!ll&&!rl&&r
101
MC/DC50%1/2
ref $$cfg{"params"} eq "HASH" and exists $$cfg{"params"}{"important_heads"}
ref $$cfg{"params"} eq "HASH" exists $$cfg{"params"}{"important_heads"}
Truth table66%2/3
A and B
A= ref $$cfg{"params"} eq "HASH"B= exists $$cfg{"params"}{"important_heads"}
ABresult
0X0
100
111
44 1 ▶ my $provider = $cfg->{model_info} ? ( $cfg->{model_info}{provider} // '' ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$$cfg{'model_info'} ? : 1 0 1
Condition50%1/2
$$cfg{"model_info"}{"provider"} // ""
l!l
01
MC/DC0%0/1
$$cfg{"model_info"}{"provider"} // ""
$$cfg{"model_info"}{"provider"}
Truth table50%1/2
A
A= $$cfg{"model_info"}{"provider"}
Aresult
11
00
45 1 ▶ return 'qk' if $provider =~ /attn/;
Branch: 1 branch
BranchTrueFalseTotal
if $provider =~ /attn/ 0 1 1
46 1 return undef;
47 }
48  
49  
50 2 ▶sub model_id {
Subroutine model_id: called CC=2 SCAR=7.1
Pod documented
51 2 my ( $self ) = @_;
52 2 ▶ my $info = $self->data->{model_info} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $info = $self->data->{"model_info"} or return undef 2 0 2
53 2 return $info->{model_id};
54 }
55  
56  
57 5 ▶sub xargs {
Subroutine xargs: called CC=10 SCAR=23.2
Pod documented
58 5 my ( $self ) = @_;
59 5 my $cfg = $self->data;
60  
61 5 ▶ if ( ref $cfg->{steering} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$cfg{"steering"} eq "HASH") 1 4 5
62 1 return { steer => $self->encode_json_text( $cfg->{steering} ) };
63 }
64  
65 4 ▶ if ( ref $cfg->{hidden_states} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$cfg{"hidden_states"} eq "HASH") 2 2 4
66 2 my $layers = $cfg->{hidden_states}{layers};
67 2 ▶ if ( ref $layers eq 'ARRAY' && @$layers ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $layers eq "ARRAY" and @$layers) 1 1 2
Condition66%2/3
ref $layers eq "ARRAY" and @$layers
!ll&&!rl&&r
011
MC/DC50%1/2
ref $layers eq "ARRAY" and @$layers
ref $layers eq "ARRAY" @$layers
Truth table66%2/3
A and B
A= ref $layers eq "ARRAY"B= @$layers
ABresult
0X0
100
111
68 1 return { output_hidden_states => $self->encode_json_text($layers) };
69 }
70 1 return { output_hidden_states => JSON::MaybeXS::true() };
71 }
72  
73 2 ▶ if ( ref $cfg->{params} eq 'HASH' && $cfg->{params}{important_heads} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$cfg{"params"} eq "HASH" and $$cfg{"params"}{"important_heads"}) 1 1 2
Condition66%2/3
ref $$cfg{"params"} eq "HASH" and $$cfg{"params"}{"important_heads"}
!ll&&!rl&&r
101
MC/DC50%1/2
ref $$cfg{"params"} eq "HASH" and $$cfg{"params"}{"important_heads"}
ref $$cfg{"params"} eq "HASH" $$cfg{"params"}{"important_heads"}
Truth table66%2/3
A and B
A= ref $$cfg{"params"} eq "HASH"B= $$cfg{"params"}{"important_heads"}
ABresult
0X0
100
111
74 1 my %layer_to_heads;
75 1 for my $pair ( @{ $cfg->{params}{important_heads} } ) {
76 4 my ( $layer, $head ) = @$pair;
77 4 push @{ $layer_to_heads{$layer} }, $head;
78 }
79 1 ▶ my $mode = $cfg->{hookq} ? ( $cfg->{hookq}{hookq_mode} // 'last_token' ) : 'last_token';
Branch: 1 branch
BranchTrueFalseTotal
$$cfg{'hookq'} ? : 1 0 1
Condition50%1/2
$$cfg{"hookq"}{"hookq_mode"} // "last_token"
l!l
10
MC/DC0%0/1
$$cfg{"hookq"}{"hookq_mode"} // "last_token"
$$cfg{"hookq"}{"hookq_mode"}
Truth table50%1/2
A
A= $$cfg{"hookq"}{"hookq_mode"}
Aresult
11
00
80 return {
81 1 output_qk => $self->encode_json_text( \%layer_to_heads ),
82 hookq_mode => $mode,
83 };
84 }
85  
86 1 return {};
87 }
88  
89 2 __PACKAGE__->meta->make_immutable;
90  
91  
92 2 1;
93  
94 __END__
« blib/lib/Langertha/Role/PluginHost.pm ↑ Summary blib/lib/Langertha/Engine/Perplexity.pm »