I think you could us any of the swarms here as a template. I would keep the swarm traits:
Swarm.
Swarm Reactions.
Swarm Resistance.
Swarm Tactics.
Swarm Vulnerabilities.
I use the AC, speed , attack bonus, ability scores, and special traits (modified as needed) of the parent creature
To determine the size, HP, number attacks/legendary actions I pick a multiple of (4) of the parent creature. And then use that total to determine the HP, size and attacks.
So for an imp, let use a swarm of 16 imps. The is roughly Large size(if the are close together, I might use Huge to give them so room to maneuver),160 HP, and 16 attacks. Give 1/4 of the attacks to its multiattack action and the same for one use of its legendary actions.
So that would get us
Imp Swarm
Huge swarm of tiny fiends, lawful evil
Armor Class 13
Hit Points 155 (22d12 + 12)
Speed 20 ft., fly 40 ft.
STR | DEX | CON | INT | WIS | CHA |
6 (-2) | 17 (+3) | 13 (+1) | 11 (+0) | 12 (+1) | 14 (+2) |
Skills Deception +7, Insight +6, Persuasion +7, Perception +11, Stealth +5
Damage Resistances cold; bludgeoning piercing and slashing
Damage Immunities fire, poison
Condition Immunities poisoned; see Swarm Resistance
Senses darkvision 120 ft., passive Perception 21
Languages Infernal, Common
Challenge ???
Devil’s Sight. Magical darkness doesn’t impede the swarm’s darkvision.
Magic Resistance. The swarm has advantage on saving throws against spells and other magical effects.
Mass Shapechanger (1/day). The swarm can use an action to polymorph into a creature of its size and CR or below. In its new form it has the Str, Dex, Con, traits and abilities of its new form, plus Devil’s sight and Magic Resistance. It can us any action and abilities of its new form, but any actions, checks, or saves that rely on Int, Wis, or Cha use the swarms abilities, not the new forms. Once the new form takes 100 hit points of damage, this effect ends and the swarm reverts back to its original form.
Swarm. The swarm can occupy another creature’s space and vice versa, and the swarm can move through any opening large enough for a Tiny imp. If the swarm is reduced to 115 hit points or less change its size to Large and it loses one use of its legendary actions. If the swarm is reduced to 77 hit points or less change its size to Medium and it loses an additional use of its legendary actions. If the swarm is reduced to 38 hit points or less, choose: 1) replace the swarm with four imps in unoccupied spaces within the former area of the swarm, or 2) keep the current statistics, but remove the Swarm Resistance trait.
Swarm Reactions. The swarm does not have reactions. Whenever a creature moves inside the space of the swarm or out of the space of the swarm, the swarm makes one sting attack with advantage targeting the triggering creature.
Swarm Resistance. The swarm has advantage on saving throws against being blinded, paralyzed, petrified, prone, restrained, or stunned. Additionally, the swarm can use its legendary actions to immediately end one condition or effect it is suffering per legendary action spent.
Swarm Tactics. The swarm has advantage on attack rolls against a creature if it is occupying the same space as the swarm.
Swarm Vulnerabilities. The swarm takes double damage from any attack that have an area of effect.
ACTIONS
Multiattack. The swarm makes four sting attacks.
Sting. Melee Weapon Attack: +5 to hit, reach 5 ft., one target.
Hit: 5 (1d4 + 3) piercing damage, and 3 (1d6) poison damage, and the target must make a DC 11 Constitution saving throw, taking 10 (3d6) poison damage on a failed save, or half as much damage on a successful one..
Invisibility. The imp swarm magically turns invisible until it attacks or until is concentration ends (as if concentrating on a spell). Any equipment worn or carried by an imp in the swarm or the swarm as a whole is invisible with it.
LEGENDARY ACTIONS
The swarm can take 3 legendary actions, choosing from the options below. Only one legendary action option can be used at a time and only at the end of another creature’s turn. The swarm regains spent legendary actions at the start of its turn.
Move. The swarm moves up to 5 feet.
Multiattack. The swarm makes four sting attacks.
PS: If you want a larger swarm of imps I also have a gargantuan
Imp swarm. If you want less, use reduce everything by 1/4 (so 12 imps = 120 HP, 3 attacks per multiattack, etc.)
I hope that helps!